moses-palmer / pynput

Sends virtual input commands
GNU Lesser General Public License v3.0
1.78k stars 247 forks source link

`uinput_device_paths` Kwarg does not work on Windows #562

Closed PowerBroker2 closed 1 year ago

PowerBroker2 commented 1 year ago

Description Tried using uinput_device_paths Kwarg to listen to only one specific keyboard, but inputs from all keyboards are "listened-to".

from pynput import keyboard

def on_press(key):
    try:
        print('alphanumeric key {0} pressed'.format(
            key.char))
    except AttributeError:
        print('special key {0} pressed'.format(
                key))

def on_release(key):
    print('{0} released'.format(
        key))
    if key == keyboard.Key.esc:
        # Stop listener
        return False

listener = keyboard.Listener(
    on_press=on_press,
    on_release=on_release,
    uinput_device_paths=[r'HID\VID_34EB&PID_1502\9&167F9EC7&0&0000'])
listener.start()

NOTE: I also tried to specify the device path as just a string (not a list of a string), but nothing changed

Platform and pynput version Windows 11 and pynput 1.7.6.

To Reproduce Use two keyboards and try to only listen to one of them on Windows

moses-palmer commented 1 year ago

Thank you for your report.

As noted in the documentation, uinput is a Linux based backend and thus does not work on Windows.

PowerBroker2 commented 1 year ago
  1. What documentation? I was only able to find this kwarg in a src docstring that didn't say anything about OS's. Not a big deal, just curious
  2. Is it possible to add this feature for windows?
moses-palmer commented 1 year ago

The documentation describes the prefixed kwargs as non-standard platform dependent options. That may be a bit unclear in the context.

I have not found a way to detect the source of the event on Windows, so adding this functionality seems infeasible.