Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

mobile: keyevent for Android #310

Merged
merged 1 commit into from Mar 22, 2013
Jump to file or symbol
Failed to load files and symbols.
+29 −0
Split
View
@@ -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;
View
@@ -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) {
View
@@ -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 = {