pythonwindowsinputtouchpad

Taking input from touchpad


Hello everyone 👋 I'm just starting to learn python and I'd like to ask is there any method to receiving input from touchpad? I've seen an Asus laptop with their touchpad become numberpad (Like the photo below) and I'm interested to know if I can do it too but for different purposes. Because I think like this. If I could access certain parts of the touchpad wouldn't it be like I can expand my keyboard to the touchpad that I rarely used ? Thank you for your attention Attachment

I have tried to look for some tutorial, video, Library, or even AI assistant like chatgpt or google bard but I can't find any solution to my problem wish anyone can help me to start appreciate your help 🙏


Solution

  • I've done this on Linux, I don't know about Microsoft, Mac etc.

    You can use evdev:

    pip install evdev
    

    Example of using it:

    import evdev
    from evdev import InputDevice, categorize, ecodes
    
    # Replace this path with the path to your touchpad device
    device_path = '/dev/input/eventX'
    
    # Open the device
    device = InputDevice(device_path)
    
    # Loop to continuously read touchpad events
    for event in device.read_loop():
        if event.type == ecodes.EV_ABS:
            # Handle absolute axis events
            abs_event = categorize(event)
            if abs_event.event.code == ecodes.ABS_X:
                print(f"X Axis: {abs_event.event.value}")
            elif abs_event.event.code == ecodes.ABS_Y:
                print(f"Y Axis: {abs_event.event.value}")
            elif abs_event.event.code == ecodes.ABS_PRESSURE:
                print(f"Pressure: {abs_event.event.value}")
        elif event.type == ecodes.EV_KEY:
            # Handle key events (like tapping)
            key_event = categorize(event)
            if key_event.keystate == 1:  # Key press
                print(f"Key {key_event.keycode} pressed")