MCPcopy
hub / github.com/appium/python-client / press_keycode

Method press_keycode

appium/webdriver/extensions/keyboard.py:87–112  ·  view source on GitHub ↗

Sends a keycode to the device. Android only. Possible keycodes can be found in http://developer.android.com/reference/android/view/KeyEvent.html. Args: keycode: the keycode to be sent to the device metastate: meta information about the keycode being

(self, keycode: int, metastate: Optional[int] = None, flags: Optional[int] = None)

Source from the content-addressed store, hash-verified

85 return self.press_keycode(keycode=keycode, metastate=metastate)
86
87 def press_keycode(self, keycode: int, metastate: Optional[int] = None, flags: Optional[int] = None) -> Self:
88 """Sends a keycode to the device.
89
90 Android only. Possible keycodes can be found
91 in http://developer.android.com/reference/android/view/KeyEvent.html.
92
93 Args:
94 keycode: the keycode to be sent to the device
95 metastate: meta information about the keycode being sent
96 flags: the set of key event flags
97
98 Returns:
99 Union['WebDriver', 'Keyboard']: Self instance
100 """
101 ext_name = 'mobile: pressKey'
102 args = {'keycode': keycode}
103 if metastate is not None:
104 args['metastate'] = metastate
105 if flags is not None:
106 args['flags'] = flags
107 try:
108 self.assert_extension_exists(ext_name).execute_script(ext_name, args)
109 except UnknownMethodException:
110 # TODO: Remove the fallback
111 self.mark_extension_absence(ext_name).execute(Command.PRESS_KEYCODE, args)
112 return self
113
114 def long_press_keycode(self, keycode: int, metastate: Optional[int] = None, flags: Optional[int] = None) -> Self:
115 """Sends a long press of keycode to the device.

Callers 3

keyeventMethod · 0.95
test_press_keycodeMethod · 0.80

Calls 4

execute_scriptMethod · 0.80
executeMethod · 0.45

Tested by 2

test_press_keycodeMethod · 0.64