# sendKeyEvent

Send a key event to the Android device.

This command is the legacy Android key event API. For new tests, prefer using `pressKeyCode()` with numeric keycodes from the Android `KeyEvent` constants.

> **Note:** Falls back to the deprecated Appium 2 protocol endpoint if the driver does not support the `mobile:` execute method.

## Usage[​](#usage "Direct link to Usage")

```
await browser.sendKeyEvent(keycode, metastate)
```

## Parameters[​](#parameters "Direct link to Parameters")

| Name                        | Type     | Details                                                                                                                                                                                           |
| --------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `keycode`                   | `string` | The keycode to send (as a string, e.g. `'3'` for Home). See [Android KeyEvent](https://developer.android.com/reference/android/view/KeyEvent) for all available keycodes.                         |
| `metastate`<br />*optional* | `string` | The meta state to apply during the key press as a string (e.g. `'1'` for Shift). See [Android KeyEvent](https://developer.android.com/reference/android/view/KeyEvent) for all meta state values. |

## Example[​](#example "Direct link to Example")

sendKeyEvent.js

```
it('should send a key event', async () => {
    // Send the Home key event (keycode '3')
    await browser.sendKeyEvent('3')
    // Send Shift+A (keycode '29', metastate '1')
    await browser.sendKeyEvent('29', '1')
})
```

## Support[​](#support "Direct link to Support")

![Support for android](/assets/images/android-d941e94d5839760141de31c8446b67ce.svg)

**Supported platforms:** Android

note

Refer to the official [Appium driver documentation](https://appium.io/docs/en/latest/ecosystem/) to see which driver versions support this command.
