Skip to content

Instantly share code, notes, and snippets.

@solarkraft
Created September 19, 2020 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save solarkraft/c26dd672e6bc5a2b80869ebb4890b593 to your computer and use it in GitHub Desktop.
Save solarkraft/c26dd672e6bc5a2b80869ebb4890b593 to your computer and use it in GitHub Desktop.
evdev touch points viewer
# needs root.
from evdev import InputDevice, categorize, ecodes
# input device (right one is nice to find using sudo evemu-describe)
dev = InputDevice('/dev/input/event14')
print(dev)
# list of x, y tuples
touches_supported = 10
touches = [(-1, -1) for _ in range(touches_supported)]
slot = 0
for event in dev.read_loop():
# react to slot changes
if event.code == ecodes.ABS_MT_SLOT:
slot = event.value
# set coordinates on right slot
if event.type == ecodes.EV_ABS:
if event.code == ecodes.ABS_MT_POSITION_X:
x = event.value
touches[slot] = (x, touches[slot][1])
if event.code == ecodes.ABS_MT_POSITION_Y:
y = event.value
touches[slot] = (touches[slot][0], y)
print(touches)
# reset coordinates (tracking id becomes -1 with a switch to the respective slot beforehand)
if event.code == ecodes.ABS_MT_TRACKING_ID and event.value == -1:
touches[slot] = (-1, -1)
print(touches)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment