Sign in to follow this  
Endemoniada

Making OnKeyDown() for DirectInput ?

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this