Original Post
🔒 Locked
Direct Input problem
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.
u'll have to use another array of bools or something to tell you if the key is down or not. something like this
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]
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]
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement