DInput: detecting when a key is pressed

Started by
3 comments, last by Quantum 23 years, 5 months ago
i know how to detect if a key is down using directinput, but i''m having trouble detecting when its pressed i want to be able to call a function that will tell me if it has been pressed this frame.. so i can hold it down and it wont repeat im doing this, but it doesn''t seem to be working
    

//.. Get the state of the keyboard and store it in Keys ..


//Set the LastKey to on, if it was previously off and is on this frame
//Set it to off if it was previously on and it is off this frame

for(int i = 0; i < sizeof(Keys); i++)
{
	if((Keys<i> & 0x80) && (!(LastKey[i] & 0x80)))
		LastKey[i] = 1;

	else if((!(Keys[i] & 0x80)) && (LastKey[i] & 0x80))
		LastKey[i] = 0;			
}
    
its probably something stupid.. but i want to get this working can somebody help?
Advertisement
I think that would work if it didn't get called so often. Basically waht I suspect happens is that you press a key and the next time your loop runs it tags it as pressed. The second time around the chances are you probably still holding the key down so

    Keys<i> & 0x80     


will be true again. This causes the input to toggle between true and false for as long as you hold the key down.

I suggest that you take a look at buffered input. It should solve all your problems since that records key presses rather than key states.

Regards,
Ralph Potter
ralph.potter@digital-magi.com, http://www.digital-magi.com



Edited by - digital-magi on October 30, 2000 8:34:50 AM
Regards,Ralph Potterralph.potter@digital-magi.com, http://www.digital-magi.com
oh, i see.

how would i go about getting buffered input to record key presses then?
Check the input examples in DirectX7 SDK..
You''re looking for: KeybdBuf.
Check my games out at:http://www.GamePlayHeaven.com
thanks! this is exactly what im after

This topic is closed to new replies.

Advertisement