boppreh / keyboard

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

All letters Unrecognized on macOS #604

Open AlexeyRogachenko opened 1 year ago

AlexeyRogachenko commented 1 year ago

Hello! I know that macOS (osX) support is experimental, but it seems that my issue, if confirmed, would mean that there is little to no support of macOS at all.

So the issue is very simple. Any attemt to press and kind of letters ("w", "T" or others) lead to error as shown on the screenshot below

Screenshot 2023-05-10 at 20 05 10

File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/keyboard/__init__.py", line 379, in send parsed = parse_hotkey(hotkey) ^^^^^^^^^^^^^^^^^^^^

File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/keyboard/__init__.py", line 344, in parse_hotkey scan_codes = key_to_scan_codes(hotkey) ^^^^^^^^^^^^^^^^^^^^^^^^^

File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/keyboard/__init__.py", line 324, in key_to_scan_codes raise ValueError('Key {} is not mapped to any known key.'.format(repr(key)), e) ValueError: ("Key 'w' is not mapped to any known key.", ValueError('Unrecognized character: w'))

UPD: Macbook Pro M1 MacOS Ventura 13.3.1 (a)

Korolen commented 1 year ago

I'm getting this as well, when trying to register my first hotkey; given that this issue didn't come up on Google when I searched for the error, yet it was at the very top of the issues list w/ date 5 days ago, I'd maybe guess it's a recent thing..? Not sure.

Do you have M1 or Intel? I'm on:

Traceback (most recent call last):
  File "/Users/tom/.pyenv/versions/3.10.7/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
Traceback (most recent call last):
  File "/Users/tom/code_tmp/fields/play/selfimproving_clay/./scripts/hotkeys.py", line 7, in <module>
    self.run()
  File "/Users/tom/.pyenv/versions/3.10.7/lib/python3.10/threading.py", line 953, in run
    keyboard.add_hotkey('ctrl+shift+r', hotkey_callback)
  File "/Users/tom/.pyenv/versions/3.10.7/lib/python3.10/site-packages/keyboard/__init__.py", line 641, in add_hotkey
    self._target(*self._args, **self._kwargs)
  File "/Users/tom/.pyenv/versions/3.10.7/lib/python3.10/site-packages/keyboard/__init__.py", line 294, in listen
    steps = parse_hotkey_combinations(hotkey)
  File "/Users/tom/.pyenv/versions/3.10.7/lib/python3.10/site-packages/keyboard/__init__.py", line 573, in parse_hotkey_combinations
    _os_keyboard.listen(self.direct_callback)
  File "/Users/tom/.pyenv/versions/3.10.7/lib/python3.10/site-packages/keyboard/_darwinkeyboard.py", line 430, in listen
    return tuple(tuple(combine_step(step)) for step in parse_hotkey(hotkey))
  File "/Users/tom/.pyenv/versions/3.10.7/lib/python3.10/site-packages/keyboard/__init__.py", line 358, in parse_hotkey
    raise OSError("Error 13 - Must be run as administrator")
OSError: Error 13 - Must be run as administrator
    steps.append(tuple(key_to_scan_codes(key) for key in keys))
  File "/Users/tom/.pyenv/versions/3.10.7/lib/python3.10/site-packages/keyboard/__init__.py", line 358, in <genexpr>
    steps.append(tuple(key_to_scan_codes(key) for key in keys))
  File "/Users/tom/.pyenv/versions/3.10.7/lib/python3.10/site-packages/keyboard/__init__.py", line 324, in key_to_scan_codes
    raise ValueError('Key {} is not mapped to any known key.'.format(repr(key)), e)
ValueError: ("Key 't' is not mapped to any known key.", ValueError('Unrecognized character: t'))
AlexeyRogachenko commented 1 year ago

Do you have M1 or Intel?

I'm on Macbook Pro M1, MacOS Ventura 13.3.1

Korolen commented 1 year ago

Wonder if the apple silicon series is what's causing the issue (no idea really). I hope someone has some insight 'cause I'd love to use this package.

On the surface it looks to be a wonderful offering of multiplatform goodness. (I'd love to have a standardized form to express my keyboard remaps and such).

wolfuoa commented 10 months ago

Looks like this project cannot map to your operating system keyboard layout. Use key codes as documented by your platform and directly send the numbers as shown in keyboard.send(56) If you find a module that wrote the key codes to their respective characters, use that. Otherwise find documentation like this

cornradio commented 7 months ago

getting this error on keyboard.add_hotkey too ,...

willywillycow commented 6 months ago

Got this problem too. A very old program of mine that worked previously broke when I tried running it now, probably something to do with recent system updates. Quite annoying.