Double Tap

BlitzMax Forums/BlitzMax Programming/Double Tap

Rimmsy(Posted 2005) [#1]
Anyone got a working double tap function? Seem to be getting stuck with the keydown() and keyhit() combination.

Any help appreciated.


Perturbatio(Posted 2005) [#2]
Graphics 640,480,0,0

Global msg:String = "No double click"
Global pause:Int

While Not KeyDown(KEY_ESCAPE)
	Cls
	
	If Doubletap(KEY_MOUSELEFT) Then 
		msg = "Double click"
		pause = MilliSecs()
	Else 
		If MilliSecs() - pause > 1000 Then msg = "No Double Click"
	EndIf
	
	DrawText(msg,0,0)
	
	Flip
Wend

End



Function DoubleTap:Int(key:Int, rate:Int = 1000)
	Global keys:Int[192]
	
	If KeyHit(key) Then
		If MilliSecs() - keys[key] <= rate Then
				keys[key] = MilliSecs()
				Return True
		Else
			keys[key] = MilliSecs()
		EndIf
	EndIf
	
	Return False
End Function



Rimmsy(Posted 2005) [#3]
Wow! Thanks a lot perty. What a great community. I was getting stuck with a combo of KeyDown but your code sample helped clear it up.

Thanks a lot. You'll get credit in my game, Perty.


Perturbatio(Posted 2005) [#4]
np :)


CGV(Posted 2005) [#5]
@ Perturbatio

Could you explain the keys[] array that you declare as Global within the function.

In C++ you can declare variables as 'static' within a function so that they'll preserve their values between function calls. Is that what this is?


Perturbatio(Posted 2005) [#6]
yes.


CGV(Posted 2005) [#7]
Thanks.