Archived

This topic is now archived and is closed to further replies.

hello_there

keyboard input

Recommended Posts

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

Share this post


Link to post
Share on other sites
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....

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites