Skip to main content
gamedev.net
🔒 Locked

Windows Keyboard Input

Started by Stealth2000 8 replies 600+ views
Original Post
Stealth2000
Stealth2000
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.
TDragon
TDragon
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]
hammerstein_02
hammerstein_02
Check the Win32 API reference, it contains all the VK_ codes.
Stealth2000
Stealth2000
I did think to try VK_D before.... that gives an error:
error C2065: ''VK_D'' : undeclared identifier

Other suggestions/functions?
Stealth2000
Stealth2000
You got it... I can''t believe I didn''t try that. I thought about it but somehow didn''t think it would convert the character to a integer.

Thanks.
davepermen
davepermen
learn to use documentation. keycodes are documented in the msdn

"take a look around" - limp bizkit
www.google.com
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia
My Page davepermen.net | My Music on Bandcamp and on Soundcloud
Teknofreek
Teknofreek
>>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
John
d000hg
d000hg
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
Teknofreek
Teknofreek
>>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
John

Topic Locked

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

Sign in to reply to this topic.