boppreh / keyboard

Hook and simulate global keyboard events on Windows and Linux.
MIT License
3.77k stars 433 forks source link

Is it possible to detect a keypress of a specific keyboard? #548

Open bertoost opened 2 years ago

bertoost commented 2 years ago

I have connected a 3rd keyboard to my macbook and I want to detect a keypress from the specific keyboard, not from the others. Is that possible at all?

Regards, Bert

fpiccinali commented 2 years ago

on linux we have a device identification :


def on_pressed_keys(e):
    print(e.to_json())
    print(keyboard._pressed_events)

    if e.device == '/dev/input/event4':
      # you are on your device

keyboard.hook(on_pressed_keys)
# Block forever, like `while True`.
keyboard.wait()
bertoost commented 2 years ago

I am working on a macbook :-)