import evdev import sys import select def main(): print("--- Touch/Input Device Verifier ---") # List devices devices = [evdev.InputDevice(path) for path in evdev.list_devices()] if not devices: print("No input devices found! Check permissions (sudo?) or connections.") return target_device = None print(f"Found {len(devices)} devices:") for i, dev in enumerate(devices): print(f" {i}: {dev.name} ({dev.phys}) - {dev.path}") # Look for the known QinHeng device if "CTP_CONTROL" in dev.name or "Touch" in dev.name: target_device = dev print("-" * 30) if target_device: print(f"Auto-selected likely touch device: {target_device.name}") dev = target_device else: # Fallback to manual selection or just pick the last one? # For now, let's ask user or pick the first one if interactive try: sel = input(f"Select device ID (0-{len(devices)-1}): ") dev = devices[int(sel)] except: print("Invalid selection. Exiting.") return print(f"\nListening to: {dev.name} ({dev.path})") print("Touch the screen now! (Press Ctrl+C to stop)") print("-" * 30) try: # Read loop for event in dev.read_loop(): if event.type == evdev.ecodes.EV_ABS: absevent = evdev.categorize(event) code = evdev.ecodes.bytype[absevent.event.type][absevent.event.code] if code == "ABS_X": print(f"X: {absevent.event.value}", end=" ") elif code == "ABS_Y": print(f"Y: {absevent.event.value}") sys.stdout.flush() elif event.type == evdev.ecodes.EV_KEY and event.code == 330: # BTN_TOUCH print(f"Touch {'DOWN' if event.value else 'UP'}") except KeyboardInterrupt: print("\nStopped.") except Exception as e: print(f"Error reading device: {e}") if __name__ == "__main__": main()