summaryrefslogtreecommitdiffstats
path: root/cmds
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2013-04-29 15:22:10 -0700
committerJeff Sharkey <jsharkey@android.com>2013-04-29 15:31:10 -0700
commit11744d15364b16a976413599933ed1b1d59e4a6f (patch)
treeecbb01b787716613b3560e5085e7f00113d15ad4 /cmds
parentf1301d86fb7f414330b08dd9514436e65ba69ceb (diff)
downloadframeworks_base-11744d15364b16a976413599933ed1b1d59e4a6f.zip
frameworks_base-11744d15364b16a976413599933ed1b1d59e4a6f.tar.gz
frameworks_base-11744d15364b16a976413599933ed1b1d59e4a6f.tar.bz2
Add longpress support to keyevent.
Change-Id: I578cb7dd910425ce07fbe56412a4dc2e0c379e65
Diffstat (limited to 'cmds')
-rw-r--r--cmds/input/src/com/android/commands/input/Input.java25
1 files changed, 17 insertions, 8 deletions
diff --git a/cmds/input/src/com/android/commands/input/Input.java b/cmds/input/src/com/android/commands/input/Input.java
index 80ac539..bb26443 100644
--- a/cmds/input/src/com/android/commands/input/Input.java
+++ b/cmds/input/src/com/android/commands/input/Input.java
@@ -57,14 +57,18 @@ public class Input {
}
} else if (command.equals("keyevent")) {
if (args.length >= 2) {
- for (int i=1; i < args.length; i++) {
- int keyCode = KeyEvent.keyCodeFromString(args[i]);
- if (keyCode == KeyEvent.KEYCODE_UNKNOWN) {
- keyCode = KeyEvent.keyCodeFromString("KEYCODE_" + args[i]);
+ final boolean longpress = "--longpress".equals(args[1]);
+ final int start = longpress ? 2 : 1;
+ if (args.length > start) {
+ for (int i = start; i < args.length; i++) {
+ int keyCode = KeyEvent.keyCodeFromString(args[i]);
+ if (keyCode == KeyEvent.KEYCODE_UNKNOWN) {
+ keyCode = KeyEvent.keyCodeFromString("KEYCODE_" + args[i]);
+ }
+ sendKeyEvent(keyCode, longpress);
}
- sendKeyEvent(keyCode);
+ return;
}
- return;
}
} else if (command.equals("tap")) {
if (args.length == 3) {
@@ -168,10 +172,15 @@ public class Input {
}
}
- private void sendKeyEvent(int keyCode) {
+ private void sendKeyEvent(int keyCode, boolean longpress) {
long now = SystemClock.uptimeMillis();
injectKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_DOWN, keyCode, 0, 0,
KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, InputDevice.SOURCE_KEYBOARD));
+ if (longpress) {
+ injectKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_DOWN, keyCode, 1, 0,
+ KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_LONG_PRESS,
+ InputDevice.SOURCE_KEYBOARD));
+ }
injectKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_UP, keyCode, 0, 0,
KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, InputDevice.SOURCE_KEYBOARD));
}
@@ -251,7 +260,7 @@ public class Input {
private void showUsage() {
System.err.println("usage: input ...");
System.err.println(" input text <string>");
- System.err.println(" input keyevent <key code number or name> ...");
+ System.err.println(" input keyevent [--longpress] <key code number or name> ...");
System.err.println(" input [touchscreen|touchpad|touchnavigation] tap <x> <y>");
System.err.println(" input [touchscreen|touchpad|touchnavigation] swipe "
+ "<x1> <y1> <x2> <y2> [duration(ms)]");