I wrote an App using the 'Activity_KeyPress' Event to react on input from a Bluetooth-Keyboard. So if you press x for example it will start a function.
Everything works fine – except if you press the Enter Key (KeyCode 66) !
By pressing the enter key, a button on the screen will be pressed automatically.
You can see how the button is pressed and the function of the button is executed. The function of the EnterKey is ignored completly.
Is there something special with the Enter KeyCode?
Ok I just figured out that the 'Activity_KeyPress' Event isn't triggered if you are pressing the Enter-Key short - it's only triggered, if you are pressing it down a little bit longer (1 sec). By pressing the key longer, the Button on the screen will be pressed AND the function of the Enter Key will be executed.
If you are pressing the Enter-Key and Holding it down the Keyboard will send the Enter Key several times. So it seams the first hit on the Enter-Key is catched by the button the second one will trigger the 'Activity_KeyPress' Event.
Heres the code:
Everything works fine – except if you press the Enter Key (KeyCode 66) !
By pressing the enter key, a button on the screen will be pressed automatically.
You can see how the button is pressed and the function of the button is executed. The function of the EnterKey is ignored completly.
Is there something special with the Enter KeyCode?
Ok I just figured out that the 'Activity_KeyPress' Event isn't triggered if you are pressing the Enter-Key short - it's only triggered, if you are pressing it down a little bit longer (1 sec). By pressing the key longer, the Button on the screen will be pressed AND the function of the Enter Key will be executed.
If you are pressing the Enter-Key and Holding it down the Keyboard will send the Enter Key several times. So it seams the first hit on the Enter-Key is catched by the button the second one will trigger the 'Activity_KeyPress' Event.
Heres the code:
B4X:
Sub Activity_KeyPress(KeyCode As Int) As Boolean
If KeyCode = KeyCodes.KEYCODE_BACK Then
t_play.Enabled = False
If MB.MediaIsPlaying Then MB.MediaStop
End If
If Layout = "Player" Then
Dim vol As Int
If KeyCode = KeyCodes.KEYCODE_X Then
vol = ph.GetVolume(ph.VOLUME_MUSIC) + 1
ph.SetVolume(ph.VOLUME_MUSIC, vol, True)
End If
If KeyCode = KeyCodes.KEYCODE_ENTER Then
vol = ph.GetVolume(ph.VOLUME_MUSIC) + 1
ph.SetVolume(ph.VOLUME_MUSIC, vol, True)
End If
Return True
End If
Return False
End Sub
Last edited: