• Advertisement

Archived

This topic is now archived and is closed to further replies.

DirectInput and Keyboard

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

I have written some code using the DirectX diks structure which interprets keyboard input from the user like this: if ( particular key is down ) do this if ( another key ) do this All is working fine but I would like to know if you can do the same thing for the key being released. I know there is a WM_KEYUP message for the window but I would really like to use DirectX to do it and I also don't want some code in my DirectInput function and some in the Windows message handler. Any ideas?, Paulcoz. Edited by - paulcoz on 1/20/00 7:08:51 PM

Share this post


Link to post
Share on other sites
Advertisement
What you are looking for is, I beleived, the buffered input feature of DirectInput. You set a size for input buffer for DirectInput, then from time, poll it, retreive the buffer values. Instead of checking the current states of the keyboard keys, now you get a list of keydowns and keyups and the time they occurred(timestamps) in sequence.
Check up buffer input in DirectInput for more information

Share this post


Link to post
Share on other sites
My solution to this is as follows:
Make three boolean arrays, one for the keys that are down, one for the keys that were down last frame, and one for keys that were just released. Right before you do your keyboard if statements, scan through the arrays and set the appropriate values. If the keys was down last frame and is not down now, set the release for that key to true, otherwise set it to false. Then set the last frame array to the current keystates.

int j;
for (j = 0; j < 256; j++)
{
if (m_KeyL[j] && !keys[j])
m_KeyR[j] = TRUE;
else
m_KeyR[j] = FALSE;
m_KeyL[j] = keys[j];
}

Good luck,
Wraith


Edited by - Wraith on 1/23/00 5:28:02 PM

Share this post


Link to post
Share on other sites
why bother with bool and scanning...
simply save the last keystate into prev or whatever you prefer to call it then just check for keydown in the previous keystate and that the key is up in the current:

if ( (state_prev[Key] & 0x80) && !(state[Key] & 0x80) ) // take action

Edited by - Staffan on 1/23/00 5:34:54 PM

Share this post


Link to post
Share on other sites

Buffered Input is definitely the way to go here.
This way you''ll only have to run through your set
of "if" statements when you get a new keypress in
the buffer rather than having to go through it
ever frame.

Share this post


Link to post
Share on other sites

  • Advertisement