- Joined
- Dec 22, 2019
- Messages
- 39
I've changed the post title from "KeyUp" to "KeyReleased."
--------------------------------------------------------------------
I've implemented the code below for my own use...
Perhaps someone will find it useful.
--------------------------------------------------------------------
I've implemented the code below for my own use...
Perhaps someone will find it useful.
Code:
Strict
Import Mojo
Class KeysDownMap<T> Extends Map<Int, T>
Method Compare:Int(key1:Int, key2:Int)
Return key1 - key2
End Method
End Class
Class Game Extends App
Private
Field keysDown:KeysDownMap<Int> = New KeysDownMap<Int>()
Public
Method AppKeyUp:Int(keyNo:Int)
Local returnValue:Int = 0
If keysDown.Contains(keyNo)
If keysDown.Get(keyNo) = 1 And KeyDown(keyNo) = 0
returnValue = 1 ' Meaning this key is up
keysDown.Remove(keyNo)
Endif
Endif
AppKeyDown(keyNo)
Return returnValue
End Method
Method AppKeyDown:Int(keyNo:Int)
Local isKeyDown:Int = KeyDown(keyNo)
If isKeyDown And keysDown.Contains(keyNo) = False
keysDown.Set(keyNo, 1)
Endif
Return isKeyDown
End Method
Method OnUpdate:Int()
If AppKeyUp(KEY_CONTROL) Then Print "Control key is up"
If AppKeyUp(KEY_A) Then Print "A key is up"
If AppKeyUp(KEY_SHIFT) Then Print "Shift key is up"
Return 0
End Method
End Class
Function Main:Int()
New Game
Return 0
End
Last edited: