Jump to content
  • Advertisement
Sign in to follow this  
reaperrar

Trying to use GetKeyboardState

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

At the begging of each game loop I fill my array of chars using GetKeyboardState. It's been working fine with other projects and now all of the sudden it seems as though it isn't. I think I'm getting the wrong values for some reason. Letters and numbers work fine, each of their values = their associated ascii values. But characters like - = [ ] \ are no longer ascii values.

[ = 219 when it should be 91 etc

Why would this be happening?

Share this post


Link to post
Share on other sites
Advertisement

At the begging of each game loop I fill my array of chars using GetKeyboardState. It's been working fine with other projects and now all of the sudden it seems as though it isn't. I think I'm getting the wrong values for some reason. Letters and numbers work fine, each of their values = their associated ascii values. But characters like - = [ ] \ are no longer ascii values.

[ = 219 when it should be 91 etc

Why would this be happening?


Did you change your keyboard layout? Maybe a program changed it, a restard might help. Or try set your keyboard language manually.

Share this post


Link to post
Share on other sites
Restart didn't change anything.

But if my keyboard layout was changed or something, wouldn't I be unable to type the characters with incorrect values?

Share this post


Link to post
Share on other sites
I'm not totally sure what's up with your program, but I can see that you are using the wrong mask value, for one. It should be 0x80 (1000 0000 in binary) and not 0xF000 (which is 1111 0000 0000 0000) as you are really only trying to test the most significant bit in the byte (unless you are looking to test the state of a toggle key (shift, caps lock, ctrl, or alt)).

For example, your 91 from above looks like this in binary: 0101 1011 and 219 looks like this: 1101 1011.
Notice that the only difference between the two is that bit on the beginning?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!