Skip to main content
GameDev.net gamedev.net
🔒 Locked

keyboard input

Started by hello_there Nov 14, 2001 at 4:41 PM 4 replies 250+ views
Original Post
hello_there
hello_there
my keyboard input doesn''t work i had a way of making it work but i forgot what that was now. it was using WMKEYDOWN but i forgot now can someone please show me how it''s done? hmmm interesting
____________How could hell be worse?
Oluseyi
Oluseyi
I''ll assume that you made a typo and actually mean WM_KEYDOWN.
hello_there
hello_there
opps yeah sorry

hmmm interesting
____________How could hell be worse?
Oluseyi
Oluseyi
Well since you know what message you''re responding to, look it up.
Gladiator
Gladiator
hello_there,

The way it works is like this:

Create a global array which has 256 boolean elements.. then use WM_KEYDOWN/WM_KEYUP to set the keys'' states.... eg:



// this is global to the program
BOOL key_buffer[256];

// ... in your Window Proc...

case WM_KEYDOWN:
{

key_buffer[wParam] = TRUE;

} break;

case WM_KEYDOWN:
{

key_buffer[wParam] = FALSE;

} break;

// ... then in your main loop you can do something like this...

while (!done)
{

...

// if escape key was pressed
if (key_buffer[VK_ESCAPE])
// give it a sign it should quit
SendMessage(hMainWnd, WM_CLOSE, 0, 0);

...

}


Hope this helps....
Alimonster
Alimonster
You can get the keystate at any time using GetAsyncKeyState(). For example:

#define KEY_IS_DOWN(x) (GetAsyncKeyState(x) & 0x8000)

if (KEY_IS_DOWN(VK_LEFT))
{
// blah
}
if (KEY_IS_DOWN(VK_RETURN))
{
// etc.
}

This uses the virtual-key codes. See MSDN for info (or the game programming genesis series here, which I think also mentions it).

Of course, if you can track the WM_KEY* messages yourself then this isn''t really necessary.

Alistair Keys

"There are two kinds of people, those who finish what they start and so on."
-- Robert Byrne

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.