Key Event
The Key Event action simulates pressing a hardware or system key on the Android device using its key code. This action can be used to trigger standard Android key events that are not covered by dedicated automation methods.
When to Use
Use this action when you want to:
- Simulate pressing the Enter key.
- Trigger the Menu key.
- Control media playback.
- Perform other supported Android key events.
Syntax
var task = suremdmjs.automate().keyEvent(
<Android Key Code>
);
suremdmjs.automate().performAction(
task,
"onSuccess",
"onFailure"
);
Parameters
| Parameter | Required | Description |
|---|---|---|
| Android Key Code | Yes | The Android key code representing the hardware or system key to simulate. |
Parameter Details
Some commonly used Android key codes include:
| Key | Key Code |
|---|---|
| Enter | 66 |
| Tab | 61 |
| Space | 62 |
| Delete (Backspace) | 67 |
| Escape | 111 |
| Menu | 82 |
note
The complete list of supported Android key codes is defined by the Android framework. Refer to the official Android KeyEvent documentation for all available values.
Example
The following example simulates pressing the Enter key.
!#suremdmjs
pressEnter();
function pressEnter() {
var task = suremdmjs.automate().keyEvent(66);
suremdmjs.automate().performAction(
task,
"keyPressed",
"keyPressFailed"
);
}
function keyPressed() {
suremdmjs.log("Enter key pressed.");
}
function keyPressFailed() {
suremdmjs.log("Unable to send key event.");
}
Expected Result
The specified Android key event is sent to the currently active application.