onKey

abstract fun onKey(keyCode: Int, event: KeyEvent): Boolean

Called when a hardware key is dispatched to a view. This allows listeners to get a chance to respond before the target view.

Key presses in software keyboards will generally NOT trigger this method, although some may elect to do so in some situations. Do not assume a software input method has to be key-based; even if it is, it may use key presses in a different way than you expect, so there is no way to reliably catch soft input key presses.

Return

True if the listener has consumed the event, false otherwise.

Parameters

keyCode

The code for the physical key that was pressed.

event

The KeyEvent object containing full information about the event.