Skip to content

Commit 22c9c6b

Browse files
committed
Merge pull request #51 from paymand/keyevent_selendroid
Added 'keyevent' since it is needed for Selendroid.
2 parents ff64efc + 76e19e2 commit 22c9c6b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

appium/webdriver/mobilecommand.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class MobileCommand(object):
3131
# Appium Commands
3232
GET_APP_STRINGS = 'getAppStrings'
3333
PRESS_KEYCODE = 'pressKeyCode'
34+
KEY_EVENT = 'keyEvent' # Needed for Selendroid
3435
LONG_PRESS_KEYCODE = 'longPressKeyCode'
3536
GET_CURRENT_ACTIVITY = 'getCurrentActivity'
3637
SET_IMMEDIATE_VALUE = 'setImmediateValue'

appium/webdriver/webdriver.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,23 @@ def hide_keyboard(self, key_name=None, key=None, strategy=None):
350350
self.execute(Command.HIDE_KEYBOARD, data)
351351
return self
352352

353+
# Needed for Selendroid
354+
def keyevent(self, keycode, metastate=None):
355+
"""Sends a keycode to the device. Android only. Possible keycodes can be
356+
found in http://developer.android.com/reference/android/view/KeyEvent.html.
357+
358+
:Args:
359+
- keycode - the keycode to be sent to the device
360+
- metastate - meta information about the keycode being sent
361+
"""
362+
data = {
363+
'keycode': keycode,
364+
}
365+
if metastate is not None:
366+
data['metastate'] = metastate
367+
self.execute(Command.KEY_EVENT, data)
368+
return self
369+
353370
def press_keycode(self, keycode, metastate=None):
354371
"""Sends a keycode to the device. Android only. Possible keycodes can be
355372
found in http://developer.android.com/reference/android/view/KeyEvent.html.
@@ -640,6 +657,9 @@ def _addCommands(self):
640657
('POST', '/session/$sessionId/touch/multi/perform')
641658
self.command_executor._commands[Command.GET_APP_STRINGS] = \
642659
('POST', '/session/$sessionId/appium/app/strings')
660+
# Needed for Selendroid
661+
self.command_executor._commands[Command.KEY_EVENT] = \
662+
('POST', '/session/$sessionId/appium/device/keyevent')
643663
self.command_executor._commands[Command.PRESS_KEYCODE] = \
644664
('POST', '/session/$sessionId/appium/device/press_keycode')
645665
self.command_executor._commands[Command.LONG_PRESS_KEYCODE] = \

0 commit comments

Comments
 (0)