boppreh / keyboard

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

Fix #585 Mac OS Ventura compatibility issue! #587

Open 0xGosu opened 1 year ago

0xGosu commented 1 year ago

[fix bug for Mac OS Ventura where value of event.name is None] Add a default layout for mac OS incase unable to detect the layout key code automatically

0xGosu commented 1 year ago

Tested with a Macbook Air M1 2020 model using latest Mac OS Ventura. Please merge with Squash commit when complete the review. Thanks!

xtremforce commented 1 year ago

command key is ok, but option key are still error.

zlaazlaa commented 11 months ago

Mac OS Ventura 13.5.1 on MacBook Pro M2 Pro, still got “KeyboardEvent(Unknown 1 down)”, event.name is None

zlaazlaa commented 11 months ago

Mac OS Ventura 13.5.1 on MacBook Pro M2 Pro, still got “KeyboardEvent(Unknown 1 down)”, event.name is None

But I can distinguish keyboard event by str(event) thought the event.name is still None. Anyway, thanks to your pr!

key_event = keyboard.read_event()
if key_event.event_type == keyboard.KEY_DOWN:
    if str(key_event) == "KeyboardEvent(shift down)":
        print("press 'left shift'")
    elif str(key_event) == "KeyboardEvent(right shift down)":
        print("press 'left shift'")
    if paused:
        if str(key_event) == "KeyboardEvent(Unknown 34 down)":
            print("press 'i'")
        elif str(key_event) == "KeyboardEvent(Unknown 40 down)":
            print("press 'k'")
        elif str(key_event) == "KeyboardEvent(Unknown 38 down)":
            print("press 'j'")
        elif str(key_event) == "KeyboardEvent(Unknown 37 down)":
            print("press 'l'")