#### Archived

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

# keyboard input

This topic is 6060 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
I''ll assume that you made a typo and actually mean WM_KEYDOWN.

opps yeah sorry

hmmm interesting

##### Share on other sites
Well since you know what message you''re responding to, look it up.

##### 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 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....

##### 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

• 40
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631371
• Total Posts
2999605
×

## Important Information

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!