keyboard
keyboard copied to clipboard
Keyboard module does not have "option" key on OSX
It is not possible to use keyboard on OSX for any shortcut that require the Option key.
Such key seems to not exist
Check the files, it is there. https://github.com/boppreh/keyboard/blob/master/keyboard/_darwinkeyboard.py
Thanks for the reply; so why do I get this error about the tuple being out of range?
keyboard.press_and_release('cmd+option+i')
/Users/user/Library/Python/3.8/lib/python/site-packages/keyboard/__init__.py:383: in send
_os_keyboard.press(scan_codes[0])
E IndexError: tuple index out of range
I am just calling keyboard.press_and_release('cmd+option+i')
; the same exact call using Shift instead of option works fine.
The value in the step variable in the init.py before the error is ((55,), (), (34,))
, while when I call cmd+shift+i, the value is ((55,), (60,), (34,))
; so for some reason the code for Option is not used.
Tracing the code, seems that the function recognize the key as ALT and normalize as Left Alt, but can't find the correct code (58) and return the empty value. I used the tuple with codes and the keypress is correctly performed. Looks like a bug to me.
I ran into the same issue. "option" is normalized to "left alt", but there's no code for "left alt", only code for "alt". I had to hack the source code, and map "option" to "option" to get it to work as highlighted in blue:
It looks like alt
is not registered in _darwinkeyboard.py
, but option
is, but the canonical_names
mapping translates option
into alt
. Regardless of which name you use, it's translated into the name that isn't registered.
I was able to hack around this by sending the actual keycode for option. Unfortunately you can't use the string hotkey representation to do this, so you have to send a list of keys to press.
desired: keyboard.send('option+y')
workaround: keyboard.send([0x3a, 'y'])
Duplicate of https://github.com/boppreh/keyboard/issues/331