pressKeyCode has been deprecated - Java-client 6.0.0


I’m wondering what is the substitute for deprecated pressKeyCode on Java-client 6.0.0. I’m currently using

((AndroidDriver) driver.getKeyboard()).pressKeyCode(AndroidKeyCode.DEL)

…to press DELETE button. Any examples?


((AndroidDriver) driver).pressKey(new KeyEvent(AndroidKey.HOME));

 * Send a key event to the device.
 * @deprecated use {@link #pressKey(KeyEvent)} instead
 * @param key code for the key pressed on the device.
default void pressKeyCode(int key) {
    CommandExecutionHelper.execute(this, pressKeyCodeCommand(key));


Thank you Ben, it works.


Hi Ben ,
I am getting error “The constructor KeyEvent(AndroidKey) is undefined”.
Can you please tell me what am I missing?


What version of Appium Java Client are you using? In 6.1.0 it should be there:

public class KeyEvent {
    private Integer keyCode;
    private Integer metaState;
    private Integer flags;

    public KeyEvent() {

    public KeyEvent(AndroidKey key) {
        this.keyCode = key.getCode();


driver.pressKey(new KeyEvent(AndroidKey.DEL));



i have tried all of these but none of them worked for me

((PressesKeyCode) driver).pressKeyCode(AndroidKeyCode.MENU); ((PressesKeyCode) driver).pressKeyCode(AndroidKeyCode.MENU, AndroidKeyMetastate.META_SHIFT_ON);
HashMap swipeObject = new HashMap(); swipeObject.put(“keycode”, 82);
((JavascriptExecutor ) driver).executeScript(“mobile: keyevent”, swipeObject);