View.IOnKeyListener.OnKey(View, Keycode, KeyEvent) Method

Definition

Called when a hardware key is dispatched to a view.

[Android.Runtime.Register("onKey", "(Landroid/view/View;ILandroid/view/KeyEvent;)Z", "GetOnKey_Landroid_view_View_ILandroid_view_KeyEvent_Handler:Android.Views.View/IOnKeyListenerInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
public bool OnKey (Android.Views.View? v, Android.Views.Keycode keyCode, Android.Views.KeyEvent? e);
[<Android.Runtime.Register("onKey", "(Landroid/view/View;ILandroid/view/KeyEvent;)Z", "GetOnKey_Landroid_view_View_ILandroid_view_KeyEvent_Handler:Android.Views.View/IOnKeyListenerInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")>]
abstract member OnKey : Android.Views.View * Android.Views.Keycode * Android.Views.KeyEvent -> bool

Parameters

v
View

The view the key has been dispatched to.

keyCode
Keycode

The code for the physical key that was pressed

e
KeyEvent

The KeyEvent object containing full information about the event.

Returns

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

Attributes

Remarks

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.

Java documentation for android.view.View.OnKeyListener.onKey(android.view.View, int, android.view.KeyEvent).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to