Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

# DialogInterface.OnKeyListener

*** ** * ** ***

` public static interface DialogInterface.OnKeyListener `   
` `

|---|
| android.content.DialogInterface.OnKeyListener |

<br />

*** ** * ** ***

Interface definition for a callback to be invoked when a key event is dispatched to this dialog. The callback will be invoked before the key event is given to the dialog.

## Summary

| ### Public methods ||
|---|---|
| ` abstract boolean` | ` https://developer.android.com/reference/android/content/DialogInterface.OnKeyListener#onKey(android.content.DialogInterface,%20int,%20android.view.KeyEvent)(https://developer.android.com/reference/android/content/DialogInterface dialog, int keyCode, https://developer.android.com/reference/android/view/KeyEvent event) ` Called when a key is dispatched to a dialog. |

## Public methods

### onKey

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract boolean onKey (DialogInterface dialog, 
                int keyCode, 
                KeyEvent event)
```

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

<br />

| Parameters ||
|---|---|
| `dialog` | `DialogInterface`: the dialog the key has been dispatched to <br /> |
| `keyCode` | `int`: the code for the physical key that was pressed <br /> |
| `event` | `KeyEvent`: the KeyEvent object containing full information about the event <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if the listener has consumed the event, `false` otherwise <br /> |