diff --git a/cmds/monkey/src/com/android/commands/monkey/MonkeySourceNetwork.java b/cmds/monkey/src/com/android/commands/monkey/MonkeySourceNetwork.java index c5b25e6b6..99e7c0760 100644 --- a/cmds/monkey/src/com/android/commands/monkey/MonkeySourceNetwork.java +++ b/cmds/monkey/src/com/android/commands/monkey/MonkeySourceNetwork.java @@ -247,13 +247,17 @@ public class MonkeySourceNetwork implements MonkeyEventSource { // Ok, it wasn't a number, see if we have a // keycode name for it keyCode = MonkeySourceRandom.getKeyCode(keyName); - if (keyCode == -1) { + if (keyCode == KeyEvent.KEYCODE_UNKNOWN) { // OK, one last ditch effort to find a match. // Build the KEYCODE_STRING from the string // we've been given and see if that key // exists. This would allow you to do "key // down menu", for example. keyCode = MonkeySourceRandom.getKeyCode("KEYCODE_" + keyName.toUpperCase()); + if (keyCode == KeyEvent.KEYCODE_UNKNOWN) { + // Still unknown + return -1; + } } } return keyCode; diff --git a/cmds/monkey/src/com/android/commands/monkey/MonkeySourceRandom.java b/cmds/monkey/src/com/android/commands/monkey/MonkeySourceRandom.java index af740b328..c18152bf0 100644 --- a/cmds/monkey/src/com/android/commands/monkey/MonkeySourceRandom.java +++ b/cmds/monkey/src/com/android/commands/monkey/MonkeySourceRandom.java @@ -102,7 +102,7 @@ public class MonkeySourceRandom implements MonkeyEventSource { * be an expensive operation. * * @param keyName the name of the KEYCODE_VALUE to lookup. - * @returns the intenger keyCode value, or -1 if not found + * @returns the intenger keyCode value, or KeyEvent.KEYCODE_UNKNOWN if not found */ public static int getKeyCode(String keyName) { return KeyEvent.keyCodeFromString(keyName); diff --git a/cmds/monkey/src/com/android/commands/monkey/MonkeySourceScript.java b/cmds/monkey/src/com/android/commands/monkey/MonkeySourceScript.java index 4748a25c2..5b050bfec 100644 --- a/cmds/monkey/src/com/android/commands/monkey/MonkeySourceScript.java +++ b/cmds/monkey/src/com/android/commands/monkey/MonkeySourceScript.java @@ -547,6 +547,9 @@ public class MonkeySourceScript implements MonkeyEventSource { if (s.indexOf(EVENT_KEYWORD_KEYPRESS) >= 0 && args.length == 1) { String key_name = args[0]; int keyCode = MonkeySourceRandom.getKeyCode(key_name); + if (keyCode == KeyEvent.KEYCODE_UNKNOWN) { + return; + } MonkeyKeyEvent e = new MonkeyKeyEvent(KeyEvent.ACTION_DOWN, keyCode); mQ.addLast(e); e = new MonkeyKeyEvent(KeyEvent.ACTION_UP, keyCode); @@ -772,7 +775,7 @@ public class MonkeySourceScript implements MonkeyEventSource { if (e.getEventTime() < 0) { return; - } + } updatedDownTime = SystemClock.uptimeMillis(); e.setDownTime(updatedDownTime); e.setEventTime(updatedDownTime);