Getting the exact TouchDown Release State

Monkey Forums/Monkey Programming/Getting the exact TouchDown Release State

xzess(Posted 2011) [#1]
Hi, how can i get the exact Release State of the Mouse or Touch?
I really need to know if the user released the Touch/Mouse

Thanks for any help on this


Tibit(Posted 2011) [#2]
I'd suggest using utoopia of course :)

Then you would do it like this:

If Mouse.Left.Released
Print "print once after left-mouse-key has been released"
End
If Mouse.Left.Pressed
Print "print once on the first frame after left-mouse-key has been pressed"
End
If Mouse.Left.IsDown
Print "print every frame that left-mouse-key is down"
End

but if you prefer not to use utoopia, here is the source code for that so you can implement your own system:

Class InputKey
	
	Method New( keyCode:Int )
		KeyCode = keyCode
	End

	Method Pressed:Bool() Property
		Return wasPressed
	End
	
	Method IsDown:Bool() Property
		Return isPressed
	End
		
	Method Released:Bool() Property
		Return wasReleased
	End	
	
Private
	Field KeyCode:Int
	
	Field wasPressedLastFrame:Bool
	Field wasPressed:Bool
	Field isPressed:Bool
	Field wasReleased:Bool
	
Public
	Method Update:Void()
		Local isPressedState:Bool = ( KeyDown( KeyCode ) > 0 )
		
		' Click?
		If isPressedState And wasPressedLastFrame = False
			wasPressed = True
		Else
			wasPressed = False
		End
		
		' Release?
		If isPressedState = False And wasPressedLastFrame = True
			wasReleased = True
		Else
			wasReleased = False
		End
		
		isPressed 			= isPressedState
		wasPressedLastFrame = isPressedState
	End
	
End


Local myInputKey:InputKey = new InputKey(MOUSE_LEFT)

Use like this:
If myInputKey.Released
Print "print once after key has been released"
End
myInputKey.Update()

Hope that helps!