• Advertisement

Archived

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

Direct Input problem

This topic is 5498 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''m using the directX input code found in the "OpenGL Game Programming" book. The code works fine except that each keystroke makes many many calls to the function assigned. Anyone know what might be the problem here? Eirik Hoem

Share this post


Link to post
Share on other sites
Advertisement
Probably because of a high frame rate the key is being polled many times a second making it impossible to hit once only. If you want one press and then release debounce the key. If you want to be able to hold it down and get reasonable but constant polling. Then Create a timer and only call you input update a few times a second.

Share this post


Link to post
Share on other sites
u'll have to use another array of bools or something to tell you if the key is down or not. something like this

              
unsigned char keys[256];
bool locked[256];
// Get key info

{
pKeyboardDevice->GetDeviceState(256, keys);
for(int i = 0; i < 256; i++)
{
if( !( keys[i] & 0x80 ) )
locked[i] = false;
}
}

{
if( ( keys[DIK_RIGHT] & 0x80 ) && !locked[DIK_RIGHT] )
{
// Move player right;

locked[DIK_RIGHT] = true;
}
}

Just loop through all the keys and check if they are up . If they are then unlock them (by making false), but if they are down then they stay locked. This was the stuff inside the if statement (the player movement in this case) gets executed once while the key is down.


:::: [ Triple Buffer V2.0 ] ::::


[edited by - IFooBar on January 31, 2003 5:59:49 PM]

Share this post


Link to post
Share on other sites

  • Advertisement