Jump to content

  • Log In with Google      Sign In   
  • Create Account


DirectInput and Keyboard


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 paulcoz   Members   -  Reputation: 230

Like
Likes
Like

Posted 20 January 2000 - 01:04 PM

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

Sponsor:

#2 _dot_   Members   -  Reputation: 160

Like
Likes
Like

Posted 20 January 2000 - 06:41 PM

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

#3 Wraith   Members   -  Reputation: 122

Like
Likes
Like

Posted 23 January 2000 - 11:26 AM

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

#4 Staffan   Members   -  Reputation: 122

Like
Likes
Like

Posted 23 January 2000 - 11:33 AM

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

#5 LordFoul   Members   -  Reputation: 122

Like
Likes
Like

Posted 27 January 2000 - 10:37 PM


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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS