Skip to content

Commit cea3fc8

Browse files
Zeros2619zeros.zhou
andauthored
Add show_touch_trace method for touch visualization (#1156)
* Add show_touch_trace method for touch visualization Added a method to show touch trace on the device screen with options for pointer location and visual feedback. * docs(readme): add usage example for show_touch_trace() * adjust the format --------- Co-authored-by: zeros.zhou <zeros.zhou@nothing.tech>
1 parent f0f3940 commit cea3fc8

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,15 @@ Note: click, swipe, drag operations support percentage position values. Example:
476476
d.open_quick_settings()
477477
```
478478

479+
* Show touch trace on device screen
480+
481+
```python
482+
# show touch trace on device screen
483+
d.show_touch_trace()
484+
# hide touch trace
485+
d.show_touch_trace(pointer_location=False, show_touches=False)
486+
```
487+
479488
### Selector
480489

481490
Selector is a handy mechanism to identify a specific UI object in the current window.

uiautomator2/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ class _Device(_BaseClient):
5151
(0, "natural", "n", 0), (1, "left", "l", 90),
5252
(2, "upsidedown", "u", 180), (3, "right", "r", 270))
5353

54+
def show_touch_trace(self, pointer_location: bool = True, show_touches: bool = True):
55+
"""
56+
Show touch trace on device screen
57+
58+
Args:
59+
pointer_location (bool): screen overlay showing current touch data
60+
show_touches (bool): show visual feedback for taps
61+
"""
62+
self.shell(f"settings put system pointer_location {int(pointer_location)}")
63+
self.shell(f"settings put system show_touches {int(show_touches)}")
64+
5465
def window_size(self):
5566
""" return (width, height) """
5667
w, h = self._dev.window_size()

0 commit comments

Comments
 (0)