#Constant False 0
#Constant True -1
Type KeyState_Type
bReleased, bHeld, bPressed As Integer
EndType
Global KeyState As KeyState_Type[255]
Global GetKey As Integer[1,255]
Function FnUpdateInput()
Local Old, New As Integer : Old = 0 : New = 1
For Key = 0 To 255
GetKey[New,Key] = GetRawKeyState(Key)
KeyState[Key].bPressed = False
KeyState[Key].bReleased = False
If Not GetKey[New,Key] = GetKey[Old,Key]
If GetKey[New]
KeyState[Key].bPressed = Not KeyState[Key].bHeld
KeyState[Key].bHeld = True
Else
KeyState[Key].bReleased = True
KeyState[Key].bHeld = False
EndIf
GetKey[Old,Key] = GetKey[New,Key]
EndIf
Next
EndFunction
Strictly speaking, this is likely how AppGameKit already implements it's Key Inputs … but essentially this is a good practise for Keyboard / Virtual Key / Controller / Mouse / etc. inputs.
The beauty of this approach though, means only ONE of these Triggers (Held / Pressed / Released) is going to be active at any given time; and we can actually quite easily extend this with an "On Demand" Timer that'll handle things such-as "How Long has this button been Held for" … so that you can have a 4th Trigger Event, such-as Push-and-Hold Triggers.
Still this is typically a "Good" approach, to handling each key' then instead of checking for Combo-States; you can simply check for the specific Trigger Event unless of course you're looking for a specific Combination; say for example for a Fighting Game where you want to check for a Quarter Circle or such.