Added in API level 1

Callback


interface Callback
android.view.KeyEvent.Callback

Summary

Public methods
abstract Boolean
onKeyDown(keyCode: Int, event: KeyEvent!)

Called when a key down event has occurred.

abstract Boolean
onKeyLongPress(keyCode: Int, event: KeyEvent!)

Called when a long press has occurred.

abstract Boolean
onKeyMultiple(keyCode: Int, count: Int, event: KeyEvent!)

Called when a user's interaction with an analog control, such as flinging a trackball, generates simulated down/up events for the same key multiple times in quick succession.

abstract Boolean
onKeyUp(keyCode: Int, event: KeyEvent!)

Called when a key up event has occurred.

Public methods

onKeyDown

Added in API level 1
abstract fun onKeyDown(
    keyCode: Int,
    event: KeyEvent!
): Boolean

Called when a key down event has occurred. If you return true, you can first call KeyEvent.startTracking() to have the framework track the event through its onKeyUp(int,android.view.KeyEvent) and also call your onKeyLongPress(int,android.view.KeyEvent) if it occurs.

Parameters
keyCode Int: The value in event.getKeyCode().
event KeyEvent!: Description of the key event.
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyLongPress

Added in API level 5
abstract fun onKeyLongPress(
    keyCode: Int,
    event: KeyEvent!
): Boolean

Called when a long press has occurred. If you return true, the final key up will have KeyEvent.FLAG_CANCELED and KeyEvent.FLAG_CANCELED_LONG_PRESS set. Note that in order to receive this callback, someone in the event change must return true from onKeyDown and call KeyEvent.startTracking() on the event.

Parameters
keyCode Int: The value in event.getKeyCode().
event KeyEvent!: Description of the key event.
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyMultiple

Added in API level 1
abstract fun onKeyMultiple(
    keyCode: Int,
    count: Int,
    event: KeyEvent!
): Boolean

Called when a user's interaction with an analog control, such as flinging a trackball, generates simulated down/up events for the same key multiple times in quick succession.

Parameters
keyCode Int: The value in event.getKeyCode().
count Int: Number of pairs as returned by event.getRepeatCount().
event KeyEvent!: Description of the key event.
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyUp

Added in API level 1
abstract fun onKeyUp(
    keyCode: Int,
    event: KeyEvent!
): Boolean

Called when a key up event has occurred.

Parameters
keyCode Int: The value in event.getKeyCode().
event KeyEvent!: Description of the key event.
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.