Skip to main content
gamedev.net
🔒 Locked

Direct Input problem

Started by rexizt Jan 31, 2003 at 3:39 PM 2 replies 550+ views
Original Post
rexizt
rexizt
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
"may the source be with you"
RatLord
RatLord
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.
IFooBar
IFooBar
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]
[size=2]aliak.net
JoeyBlow2
JoeyBlow2
Use Buffered Input along with Unbuffered. They can both be used simultaneously.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.