Archived

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

Stealth2000

Windows Keyboard Input

Recommended Posts

Okay. I''m using NeHe''s OpenGL basecode which maps the keyboard keys like so: // Key down case WM_KEYDOWN: { keys[wParam] = true; // Mark key down as true return 0; } I understand that you can then check input for a key like so: if (keys[VK_UP]) dosomething; What I don''t know is how to tell if an A-Z key is pressed (or 0-9). Is there a virtual keycode for those keys too? Thanks. P.S. I know I should probably use DirectInput or something, but I''m not at that stage of development (or learning) yet.

Share this post


Link to post
Share on other sites
Yeah, I'm pretty sure you just check with "VK_(char)" where (char) is the character you want to check, like so:

//checks for the key "d" being pressed
if(keys[VK_D])
DoSomeCode();


This won't tell you whether shift or alt or ctrl or any of those keys are being pressed, just whether the button labeled "D" is being pressed.

EDIT: This is best used in a graphics intensive program or game, where a character being pressed fires a weapon or something. If you want to have text input, make use of the WM_CHAR message.

Twilight Dragon
Win32 API Programmer
www.freewebz.com/j-world

[edited by - TDragon on August 12, 2002 3:58:09 PM]

Share this post


Link to post
Share on other sites
>>EDIT: This is best used in a graphics intensive program or game, where a character being pressed fires a weapon or something. If you want to have text input, make use of the WM_CHAR message<<

Just out of curiosity, why is it better to use WM_CHAR for text input? I''m not disagreeing or anything, I just don''t know why it''d be easier that way?

-John

Share this post


Link to post
Share on other sites
The keyup/down messages just tell you the state of the key. WM_CHAR says a keypress (press-release) has happened so you nknow how many characters to print.

All the VK_key codes are in the docs, but not all work for me. I''m using the arrow keys and ESC (VK_UP etc) and these work fine. However if I use the codes for a and z it doesn''t recognise them and I must instead check for the value (0x54 or something). Are some keys in different include files to others?



Read about my game, project #1
NEW (13th August): A new screenshot is up, plus diaries for week #3


John 3:16

Share this post


Link to post
Share on other sites
>>The keyup/down messages just tell you the state of the key. WM_CHAR says a keypress (press-release) has happened so you nknow how many characters to print.<<

Ah, ok that makes decent sense. What if you''re using buffered input with the keyboard though...will that give you the same thing that WM_CHAR would?

The reason I''m asking is because I''m just starting to mess with DirectInput. And since I''m already moving all the game input stuff over to it, it seems like it''d be nice to have the text input there as well. Just so it''s all in the same place. However, if it''s a big hassle to get DirectInput to recognize keyboard input that would work well for typing messages then I suppose I probably should just leave that stuff over in WM_CHAR.

...just curious

-John

Share this post


Link to post
Share on other sites