diff --git a/android/bootstrap/src/io/appium/android/bootstrap/handler/PressKeyCode.java b/android/bootstrap/src/io/appium/android/bootstrap/handler/PressKeyCode.java index ee50e4b7d..7ef9e7e0a 100644 --- a/android/bootstrap/src/io/appium/android/bootstrap/handler/PressKeyCode.java +++ b/android/bootstrap/src/io/appium/android/bootstrap/handler/PressKeyCode.java @@ -1,16 +1,23 @@ package io.appium.android.bootstrap.handler; +import com.android.uiautomator.core.UiDevice; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + import io.appium.android.bootstrap.AndroidCommand; import io.appium.android.bootstrap.AndroidCommandResult; import io.appium.android.bootstrap.CommandHandler; -import com.android.uiautomator.core.UiDevice; - /** * This handler is used to PressKeyCode. * */ public class PressKeyCode extends CommandHandler { + public Integer keyCode; + public Integer metaState; /* * @param command The {@link AndroidCommand} used for this handler. @@ -23,13 +30,20 @@ public class PressKeyCode extends CommandHandler { * bootstrap.AndroidCommand) */ @Override - public AndroidCommandResult execute(final AndroidCommand command) { + public AndroidCommandResult execute(final AndroidCommand command) throws JSONException { try { - UiDevice.getInstance().pressKeyCode( - (Integer) command.params().get("keycode")); + final Hashtable params = command.params(); + keyCode = (Integer) command.params().get("keycode"); + + if (params.get("metastate") != JSONObject.NULL) { + metaState = (Integer) command.params().get("metastate"); + } + + UiDevice.getInstance().pressKeyCode(keyCode, metaState); + return getSuccessResult(true); } catch (final Exception e) { return getErrorResult(e.getMessage()); } } -} \ No newline at end of file +} diff --git a/app/android.js b/app/android.js index c0cf5e31d..d79ec7083 100644 --- a/app/android.js +++ b/app/android.js @@ -74,8 +74,8 @@ Android.prototype.fastReset = function(cb) { ], cb); }; -Android.prototype.keyevent = function(keycode, cb) { - this.proxy(["pressKeyCode", keycode], cb); +Android.prototype.keyevent = function(keycode, metastate, cb) { + this.proxy(["pressKeyCode", {keycode: keycode, metastate: metastate}], cb); }; Android.prototype.start = function(cb, onDie) { diff --git a/app/ios.js b/app/ios.js index 90ea4d29b..7fd1565d5 100644 --- a/app/ios.js +++ b/app/ios.js @@ -1130,7 +1130,7 @@ IOS.prototype.submit = function(elementId, cb) { } }; -IOS.prototype.keyevent = function(keycode, cb) { +IOS.prototype.keyevent = function(keycode, metastate, cb) { cb(new NotImplementedError(), null); };