keyboard input

Started by
4 comments, last by hello_there 22 years, 5 months ago
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?
Advertisement
I''ll assume that you made a typo and actually mean WM_KEYDOWN.
opps yeah sorry

hmmm interesting
____________________________________________________________How could hell be worse?
Well since you know what message you''re responding to, look it up.
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 programBOOL 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....
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

This topic is closed to new replies.

Advertisement