Jump to content

  • Log In with Google      Sign In   
  • Create Account

Ignoring held down keys


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
6 replies to this topic

#1 Fundy Glostna   Members   -  Reputation: 122

Like
Likes
Like

Posted 18 February 2002 - 11:30 AM

I''ve acquired a keyboard device with DirectInput, and every frame I use GetDeviceState and save the keyboard state in an array. I can detect if a key is pressed easily, using
  
  if(keystate[DIK_KEYID] & 0x80) {//do the stuff}  

  
But I only want the program to "do the stuff" if the specified key has been just been pressed, in the instantaneous frame, and is not being held down.

Sponsor:

#2 pizza box   Members   -  Reputation: 168

Like
Likes
Like

Posted 18 February 2002 - 11:56 AM

I''m not too keen on DirectInput, so there might be a different solution, but maybe you can check if the keystate is inactive right after the first if statement, such as:

if ( !keystate[ DIK_KEYID ] & 0x80 )

and then have it do something. But it might be too sudden for the user to release the key.

#3 Fundy Glostna   Members   -  Reputation: 122

Like
Likes
Like

Posted 18 February 2002 - 12:01 PM

Errr... no that can''t work. Usually, when you press a key normally, it is held down for a few frames. I only wan''t to capture the event at the instance of the key being pushed down, not after it is held. (Ex. pressing space to shoot, but holding down space doesn''t cause you to shoot continously)

#4 Fundy Glostna   Members   -  Reputation: 122

Like
Likes
Like

Posted 18 February 2002 - 12:01 PM

Errr... no that can''t work. Usually, when you press a key normally, it is held down for a few frames. I only wan''t to capture the event at the instance of the key being pushed down, not after it is held. (Ex. pressing space to shoot, but holding down space doesn''t cause you to shoot continously)

#5 Fundy Glostna   Members   -  Reputation: 122

Like
Likes
Like

Posted 18 February 2002 - 12:01 PM

Errr... no that can''t work. Usually, when you press a key normally, it is held down for a few frames. I only wan''t to capture the event at the instance of the key being pushed down, not after it is held. (Ex. pressing space to shoot, but holding down space doesn''t cause you to shoot continously)

#6 krez   GDNet+   -  Reputation: 443

Like
Likes
Like

Posted 18 February 2002 - 12:11 PM

you''ll have to store another flag somewhere to tell if the key was pressed last frame already... i.e. have another array parallel to your keystate one, and check that ("keyalreadydown" is a boolean array here):

if((keystate[DIK_KEYID] & 0x80) && keyalreadydown[DIK_KEYID])
{//do the stuff}



--- krez (krezisback@aol.com)

#7 Mulligan   Members   -  Reputation: 378

Like
Likes
Like

Posted 18 February 2002 - 01:30 PM

// RIGHT arrow
// Just know that RightKeyDown has to remain when the function ends. i.e ( make it static)
if( keystate[DIK_KEYID] & 0x80 )
{
if( m_RightKeyDown == false )
{
RightKeyDown = true;
//Add code here
}
}
else
RightKeyDown = false;




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