Skip to content

Commit

Permalink
Merge pull request #310 from bootstraponline/mobile_keyevent
Browse files Browse the repository at this point in the history
mobile: keyevent for Android
  • Loading branch information
jlipps committed Mar 22, 2013
2 parents 5fb3dc5 + 1fc3197 commit d8e014e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app/android.js
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions app/controller.js
Expand Up @@ -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('');

Expand Down Expand Up @@ -622,6 +627,7 @@ var mobileCmdMap = {
, 'findAndAct': exports.findAndAct
, 'setValue' : exports.setValueImmediate
, 'reset' : exports.reset
, 'keyevent' : exports.keyevent
};

exports.produceError = function(req, res) {
Expand Down
4 changes: 4 additions & 0 deletions app/ios.js
Expand Up @@ -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 = {
Expand Down

0 comments on commit d8e014e

Please sign in to comment.