Sub Activity_KeyPress (KeyCode As Int) As Boolean
If KeyCode = Controller.KEYCODE_DPAD_LEFT AND Controller.Btn_Press <> Controller.KEYCODE_DPAD_LEFT Then
Controller.Btn_Press = Controller.KEYCODE_DPAD_LEFT
Controller.KeyBuffer = Controller.KeyBuffer & "L"
End If
If KeyCode = Controller.KEYCODE_DPAD_RIGHT AND Controller.Btn_Press <> Controller.KEYCODE_DPAD_RIGHT Then
Controller.Btn_Press = Controller.KEYCODE_DPAD_RIGHT
Controller.KeyBuffer = Controller.KeyBuffer & "R"
End If
If KeyCode = Controller.KEYCODE_DPAD_UP AND Controller.Btn_Press <> Controller.KEYCODE_DPAD_UP Then
Controller.Btn_Press = Controller.KEYCODE_DPAD_UP
Controller.KeyBuffer = Controller.KeyBuffer & "U"
End If
If KeyCode = Controller.KEYCODE_DPAD_DOWN AND Controller.Btn_Press <> Controller.KEYCODE_DPAD_DOWN Then
Controller.Btn_Press = Controller.KEYCODE_DPAD_DOWN
Controller.KeyBuffer = Controller.KeyBuffer & "D"
End If
End Sub
Sub Activity_KeyUp (KeyCode As Int) As Boolean
If KeyCode = Controller.KEYCODE_DPAD_LEFT Then
Controller.removeKey("L")
End If
If KeyCode = Controller.KEYCODE_DPAD_RIGHT Then
Controller.removeKey("R")
End If
If KeyCode = Controller.KEYCODE_DPAD_UP Then
Controller.removeKey("U")
End If
If KeyCode = Controller.KEYCODE_DPAD_DOWN Then
Controller.removeKey("D")
End If
End Sub
'Removes a KeyString from the controller's KeyBuffer
Sub removeKey(KeyString As String)
If Not(Controller.KeyBuffer.IndexOf(KeyString) = -1) Then
Dim Part1, Part2 As String
For i = 0 To (Controller.KeyBuffer.IndexOf(KeyString) - 1)
Part1 = Part1 & Controller.KeyBuffer.CharAt(i)
Next
For i = (KeyBuffer.IndexOf(KeyString) + KeyString.Length) To (KeyBuffer.Length - 1)
Part2 = Part2 & Controller.KeyBuffer.CharAt(i)
Next
Controller.KeyBuffer = Part1 & Part2
End If
End Sub