Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add long_press, close #889 #978

Merged
merged 1 commit into from
May 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions uiautomator2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,23 @@
key, meta) if meta else self.jsonrpc.pressKeyCode(key)
else:
return self.jsonrpc.pressKey(key)

def long_press(self, key: Union[int, str]):
"""
long press key via name or key code

Args:
key: key name or key code

Examples:
long_press("home") same as "adb shell input keyevent --longpress KEYCODE_HOME"
"""
with self._operation_delay("press"):
if isinstance(key, int):
self.shell("input keyevent --longpress %d" % key)

Check warning on line 502 in uiautomator2/__init__.py

View check run for this annotation

Codecov / codecov/patch

uiautomator2/__init__.py#L502

Added line #L502 was not covered by tests
else:
key = key.upper()
self.shell(f"input keyevent --longpress {key}")

Check warning on line 505 in uiautomator2/__init__.py

View check run for this annotation

Codecov / codecov/patch

uiautomator2/__init__.py#L504-L505

Added lines #L504 - L505 were not covered by tests

def screen_on(self):
self.jsonrpc.wakeUp()
Expand Down