Skip to main content
GameDev.net gamedev.net
🔒 Locked

GetKeyState() problem

Started by Oni Sephiroth Oct 1, 2010 at 10:04 AM 4 replies 1.8k views
Original Post
Oni Sephiroth
Oni Sephiroth
I'm having some trouble getting GetKeyState() to work properly. I need it to detect letters and numbers, which it's not doing. It detects the enter key, caps lock, shift, tab, etc but nothing for letters and numbers. Here's what I'm doing..

void HVSTInput::CkeyboardTrigger::pollKeys(){    for (int i = 0; i < 128; i++)    {        _keyboard->setKeyState();    }}


First there's this, which runs from 0 to 127, checking 128 different "keys."

void HVSTInput::CKey::setKeyState(){    _previousState = _currentState;    _currentState = GetKeyState(_key);}


Then this just sets the state of the key using GetKeyState, where _key == i from the loop in pollKeys() method. Now I've looked on MSDN which says to use the ascii value for letters and numbers, which is what I thought I was doing here. Yet, only the keys that I mentioned above are actually triggering.
Kylotan
Kylotan
How are you sure that it's not picking up the keypresses?

Any reason you don't use GetKeyboardState?
Oni Sephiroth
Oni Sephiroth
I threw a breakpoint in where I'm actually checking the state of the key. It doesn't break when I press a letter key, but it does for others. I'll look into GetKeyboardState()
Atrix256
Atrix256
For numbers make sure you are checking for '9' instead of 9

For letters, if you have been trying lower case, try upper case. If you have been trying upper case try lowercase.

Also there might be some good info here for you (:

http://www.gamedev.net/community/forums/topic.asp?topic_id=24296
Oni Sephiroth
Oni Sephiroth
Wouldn't the for loop cover all of those though? I've tried casting the _key variable to a char as well and that didn't do me any good either.
Kylotan
Kylotan
The loop should cover all of those. The numbers have ASCII values 48 to 57. I suggest a breakpoint in CKey::setKeyState() to see if that triggers when you press a number key. Or some good old-fashioned printf debugging.

Topic Locked

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

Sign in to reply to this topic.