Send key event (FR)

Perfecto Command

mobile:key:event

Purpose

Sends a keyboard event to the device. Uses standard Android keycodes. Key codes and metastates are defined by Android.

For example: Key code = 29 and the Metastate = 1 will print an "A"; Key code = 29 and the Metastate = 0 will print an "a"

Parameters

Name Type Possible Values Description
key Integer

See this KeyEvent article

(Required) The key code key event to send to the device.
metastate Integer

See this MetaKeyKeyListener article

The metastate key event to send to the device.

Return Value

true - if successful

Exceptions

None

Examples

Copy

Java sample

Map<String, Object> pars = new HashMap<>();
pars.put("key", "29");
pars.put("metastate", "0");
String reStr = (String) driver.executeScript("mobile:key:event", pars);
Copy

C# sample

Dictionary<String, Object> pars = new Dictionary<String, Object>();
pars.Add("key", "32");
String reStr = (String) driver.ExecuteScript("mobile:key:event", pars);