Android Question Disable ESC key on physical keyboard

mauro vicamini

Active Member
Licensed User
Longtime User
Hello everyone,
I need to disable the ESC key in a totem Android app that use a physical keyboard.
How can achive it? (pls don't tell me to physically remove the ESC button...:)).

Thanks for your attention.

Mauro
 

DonManfred

Expert
Licensed User
Longtime User
Android does not have a "ESC Key". So there is no way to disable it.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Could you not override the onKeyDown / OnKeyUp and simply consume the key event if the keycode is KEYCODE_ESCAPE.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
You need to catch the KeyCode value in debug. If it returns value such as 27, then you may able to handle the event such as returning False in Activity_KeyPress event.

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        Return B4XPages.Delegate.Activity_KeyPress(KeyCode)
    End If
    B4XPages.GetManager.RaiseEvent(B4XPages.GetManager.GetTopPage, "B4XPage_KeyPress", Array(KeyCode))
    Return False
End Sub

https://www.b4x.com/android/forum/threads/b4xpages-intercepting-keypress.139118/#post-880705
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
on my keyboard, hitting the ESC key = android's home button, which - i understand - cannot be trapped. at least not easily, from what i've read. i've tried with inline hooks (_oncreate, _onkeydown, onkeyup), and dispatchkeyevent. key touches on the physical keyboard using these methods register fine except when i hit esc: right to user close(false) with no indication of the keycode or scancode was when i touch esc. in other words, even though there is a KeyEvent.KEYCODE_ESCAPE, code in onkeyup or onkeydown never gets a chance to evaluate which key was touched. app is closed.

i'm led to understand that you have to setcontentview() and pass the view (presumably an edittext), but setconteview is already run when the app launches. whether or not successfully using setcontentview() to the edittext (instead of the layout) has any effect on trapping the esc key i don't know.
 
Upvote 0
Top