Skip to content

Most visited

Recently visited

navigation
Added in API level 1

KeyEvent.Callback

public static interface KeyEvent.Callback

android.view.KeyEvent.Callback
Known Indirect Subclasses


Summary

Public methods

abstract boolean onKeyDown(int keyCode, KeyEvent event)

Called when a key down event has occurred.

abstract boolean onKeyLongPress(int keyCode, KeyEvent event)

Called when a long press has occurred.

abstract boolean onKeyMultiple(int keyCode, int count, KeyEvent event)

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(int keyCode, KeyEvent event)

Called when a key up event has occurred.

Public methods

onKeyDown

Added in API level 1
boolean onKeyDown (int keyCode, 
                KeyEvent event)

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, KeyEvent) and also call your onKeyLongPress(int, KeyEvent) if it occurs.

Parameters
keyCode int: The value in event.getKeyCode().
event KeyEvent: Description of the key event.
Returns
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
boolean onKeyLongPress (int keyCode, 
                KeyEvent event)

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

Parameters
keyCode int: The value in event.getKeyCode().
event KeyEvent: Description of the key event.
Returns
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
boolean onKeyMultiple (int keyCode, 
                int count, 
                KeyEvent event)

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.
Returns
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
boolean onKeyUp (int keyCode, 
                KeyEvent event)

Called when a key up event has occurred.

Parameters
keyCode int: The value in event.getKeyCode().
event KeyEvent: Description of the key event.
Returns
boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.