Last updated: Aug 02, 2017 12:14
By Daniel Tourgman
Use pressKeyCode() method for Appium or mobile:key:event Perfecto command for Selenium to send special key codes to the device.
Android devices that run versions above 5.0 support KeyEvents, where each KeyEvent corresponds to an action from the keyboard or the special system keys of the device. The code samples below demonstrate how to send Key events such as the Enter/Search Key and the Backspace Key to an Android device.
Transmitting the KeyEvent code to the device is performed slightly differently for each of the testing environment that you are working in:
- Selenium RemoteWebDriver - use the mobile:key:event Perfecto command with driver.executeScript().
- Appium AndroidDriver - use the pressKeyCode() method.
- UFT - use the SendKeyEvent method of the Device.
Remote Web Driver
Android KeyCodes List
The following is a partial list of some commonly used KeyCodes:
- 'a' - 'z' --> 29 - 54
- '0' - '9'--> 7 - 16
- SPACE --> 62
- ENTER ---> 66
- BACKSPACE --> 67
- BACK --> 4
- CALL --> 5
- ENDCALL --> 6
You can find a complete list of Key Codes and an explanation here: