From 1fc319799c1bde4da6cad27762d831f6a2cda2eb Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Fri, 22 Mar 2013 17:56:41 -0400 Subject: [PATCH] Add keyevent for Android --- app/android.js | 19 +++++++++++++++++++ app/controller.js | 6 ++++++ app/ios.js | 4 ++++ 3 files changed, 29 insertions(+) diff --git a/app/android.js b/app/android.js index 2664149abcc..03a81e97f93 100644 --- a/app/android.js +++ b/app/android.js @@ -47,6 +47,25 @@ Android.prototype.fastReset = function(cb) { this.adb.runFastReset(function(err) { if (err) return cb(err); return cb(null); }); }; +Android.prototype.keyevent = function(keycode, cb) { + // keycode must be an int. + var cmd = 'adb shell input keyevent ' + parseInt(keycode, 10); + logger.info(cmd); + exec(cmd, {}, function(err, stdout, stderr) { + if (err) { + logger.warn(stderr); + return cb(null, { + status: status.codes.UnknownError.code + , value: null + }); + } + cb(null, { + status: status.codes.Success.code + , value: null + }); + }); +}; + Android.prototype.start = function(cb, onDie) { if (typeof onDie === "function") { this.onStop = onDie; diff --git a/app/controller.js b/app/controller.js index f0d7f596845..c7bda0b043a 100644 --- a/app/controller.js +++ b/app/controller.js @@ -343,6 +343,11 @@ exports.getPageIndex = function(req, res) { req.device.getPageIndex(elementId, getResponseHandler(req, res)); }; +exports.keyevent = function(req, res) { + var keycode = req.body.keycode; + req.device.keyevent(keycode, getResponseHandler(req, res)); +}; + exports.keys = function(req, res) { var keys = req.body.value.join(''); @@ -622,6 +627,7 @@ var mobileCmdMap = { , 'findAndAct': exports.findAndAct , 'setValue' : exports.setValueImmediate , 'reset' : exports.reset + , 'keyevent' : exports.keyevent }; exports.produceError = function(req, res) { diff --git a/app/ios.js b/app/ios.js index b7610d30792..f2301ed5eb5 100644 --- a/app/ios.js +++ b/app/ios.js @@ -713,6 +713,10 @@ IOS.prototype.submit = function(elementId, cb) { } }; +IOS.prototype.keyevent = function(keycode, cb) { + cb(new NotImplementedError(), null); +}; + IOS.prototype.complexTap = function(tapCount, touchCount, duration, x, y, elementId, cb) { var command , options = {