Skip to content

Commit 1eafb3b

Browse files
committed
Merge pull request #21 from paymand/long_press_keycode
Renamed keyevent to press_keycode and added long_press_keycode.
2 parents d215b97 + 2d25554 commit 1eafb3b

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ Android only.
375375
376376
```python
377377
# sending 'Home' key event
378-
driver.keyevent(3)
378+
driver.press_keycode(3)
379379
```
380380
381381

appium/webdriver/mobilecommand.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class MobileCommand(object):
2222

2323
# Appium Commands
2424
GET_APP_STRINGS = 'getAppStrings'
25-
KEY_EVENT = 'keyEvent'
25+
PRESS_KEYCODE = 'pressKeyCode'
26+
LONG_PRESS_KEYCODE = 'longPressKeyCode'
2627
GET_CURRENT_ACTIVITY = 'getCurrentActivity'
2728
SET_IMMEDIATE_VALUE = 'setImmediateValue'
2829
PULL_FILE = 'pullFile'

appium/webdriver/webdriver.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def hide_keyboard(self, key_name=None):
337337
self.execute(Command.HIDE_KEYBOARD, data)
338338
return self
339339

340-
def keyevent(self, keycode, metastate=None):
340+
def press_keycode(self, keycode, metastate=None):
341341
"""Sends a keycode to the device. Android only. Possible keycodes can be
342342
found in http://developer.android.com/reference/android/view/KeyEvent.html.
343343
@@ -353,6 +353,22 @@ def keyevent(self, keycode, metastate=None):
353353
self.execute(Command.KEY_EVENT, data)
354354
return self
355355

356+
def long_press_keycode(self, keycode, metastate=None):
357+
"""Sends a long press of keycode to the device. Android only. Possible keycodes can be
358+
found in http://developer.android.com/reference/android/view/KeyEvent.html.
359+
360+
:Args:
361+
- keycode - the keycode to be sent to the device
362+
- metastate - meta information about the keycode being sent
363+
"""
364+
data = {
365+
'keycode': keycode
366+
}
367+
if metastate != None:
368+
data['metastate'] = metastate
369+
self.execute(Command.LONG_PRESS_KEYCODE, data)
370+
return self
371+
356372
@property
357373
def current_activity(self):
358374
"""Retrieves the current activity on the device.
@@ -519,8 +535,10 @@ def _addCommands(self):
519535
('POST', '/session/$sessionId/touch/multi/perform')
520536
self.command_executor._commands[Command.GET_APP_STRINGS] = \
521537
('GET', '/session/$sessionId/appium/app/strings')
522-
self.command_executor._commands[Command.KEY_EVENT] = \
523-
('POST', '/session/$sessionId/appium/device/keyevent')
538+
self.command_executor._commands[Command.PRESS_KEYCODE] = \
539+
('POST', '/session/$sessionId/appium/device/press_keycode')
540+
self.command_executor._commands[Command.LONG_PRESS_KEYCODE] = \
541+
('POST', '/session/$sessionId/appium/device/long_press_keycode')
524542
self.command_executor._commands[Command.GET_CURRENT_ACTIVITY] = \
525543
('GET', '/session/$sessionId/appium/device/current_activity')
526544
self.command_executor._commands[Command.SET_IMMEDIATE_VALUE] = \

test/functional/android/appium_tests.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@ def test_app_strings(self):
3737
strings = self.driver.app_strings
3838
self.assertEqual(u'You can\'t wipe my data, you are a monkey!', strings[u'monkey_wipe_data'])
3939

40-
def test_keyevent(self):
40+
def test_press_keycode(self):
4141
# not sure how to test this.
42-
self.driver.keyevent(176)
42+
self.driver.press_keycode(176)
43+
44+
def test_long_press_keycode(self):
45+
# not sure how to test this.
46+
self.driver.long_press_keycode(176)
4347

4448
def test_current_activity(self):
4549
activity = self.driver.current_activity

0 commit comments

Comments
 (0)