Jump to content
  • Advertisement
Sign in to follow this  

Making OnKeyDown() for DirectInput ?

This topic is 4058 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

Hi guys, This is the best I could come up with: BYTE key_state[256]; BOOL key_down[256]; void OnKeyDown(int key) { // handle the key if(key == DIK_LSHIFT() { ... } if(key == DIK_DELETE) { ... } // all the other keys I'm using ... ... } void Heartbeat() { // get device state... // check left-shift if(key_state[DIK_LSHIFT] & 0x80){ if(!key_down[DIK_LSHIFT]){ key_down[DIK_LSHIFT]=TRUE; } } else{ key_down[DIK_LSHIFT]=FALSE; } // check delete if(key_state[DIK_DELETE] & 0x80){ if(!key_down[DIK_DELETE]){ key_down[DIK_DELETE]=TRUE; OnKeyDown(DIK_DELETE); } } else{ key_down[DIK_DELETE]=FALSE; } // check all the other keys I'm using ... ... } Well, it's not bad and I can put the Heartbeat() part in a loop and check all 256 keys but I'm wondering if there is a better way. Thanks.

Share this post

Link to post
Share on other sites
You are using Immediate Data, right?

Well, for the way you'll be using it I would recomend Buffered Data. This means that DirectInput won't give you the state of all the keys but instead will give you the changes on the keys. However I haven't used it, but I read about...

Here is the link to the MSDN pages:

This will give you an insight of both data methods...
Buffered and Immediate Data

This will give you an Idea of how buffered data works with the keyboard...
Buffered Keyboard Data

And this is an example from the SDK, that will let you see the difference within Buffered and Immediate Data
Keyboard Sample

Hope it helps... :)

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!