Android Question Handling Enter key from PC keyboard

ddk1

Member
Licensed User
Basically same issue as old thread, Problems with KeyCode 66 (Enter)
In that post they were using a bluetooth keyboard. In my case, its running my app in Windows Subsystem for Android on Windows 11.
In my app, there is no edittext etc so I never see the android onscreen keyboard. Instead I have only onscreen buttons. But I want to accept keystrokes, namely numbers and the Enter key.
So to make it work in Win11, I added the KeyPress event and could then map keystrokes to onscreen buttons. The problem is, that the Enter key does not always trigger the KeyPress event. When it doesn't, instead, it appears to press one of the onscreen buttons. If I disable that button, it just does the same with a different button. So it appears there is such a thing as a 'default' button that gets pressed.
I found in another thread where they ran code Dim jo as JavaObject = MyButton -> jo.RunMethod("setDefaultButton",Array(True)) but this wasn't accepted in B4A.

For anyone who come across this, I applied the following simple workaround.
I took the 'default' button and renamed it, and made it small & hid it behind another button. So technically it was still 'visible' and triggered when I pressed Enter. When it triggered, I had it call the event I actually wanted (btnEquals_Click). And I created another button that I put in place and renamed as that original button.
 
Top