boppreh / keyboard

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

Segmentation Fault on macOS #619

Open jeanCarloMachado opened 8 months ago

jeanCarloMachado commented 8 months ago

Hello Community,

Firstly, thank you for your hard work on this incredibly useful library. I've encountered an issue when using it on macOS that I'd like to report. I am experiencing a segmentation fault when I run the following code snippet:

import keyboard

keyboard.add_hotkey('caps lock', lambda: print("foo"))
keyboard.wait()

I get the following error message:

zsh: segmentation fault  python3

I'm running this on a Mac. I've tried searching for similar issues but haven't come across a solution yet. Any guidance on this would be greatly appreciated.

Thanks in advance!

qent commented 7 months ago

same trouble

destroy314 commented 7 months ago

I use python -X faulthandler to located file ".../keyboard/_darwinkeyboard.py", line 134 cause the Bus error 10 and just comment that line.

Nelson-Gon commented 7 months ago

Yep, this breaks MacOS

Catyre commented 6 months ago

I use python -X faulthandler to located file ".../keyboard/_darwinkeyboard.py", line 134 cause the Bus error 10 and just comment that line.

# This breaks "import keyboard" on macOS Sonoma (M2)
Carbon.CFDataGetBytes(k_layout, CFRange(0, k_layout_size), ctypes.byref(k_layout_buffer))

Can confirm, just discovered this myself. Although I can import it fine now after commenting that line out, I'm not sure what side effects there would be down the road as I continue to use this library

amannirala13 commented 3 months ago

I use python -X faulthandler to located file ".../keyboard/_darwinkeyboard.py", line 134 cause the Bus error 10 and just comment that line.

This works.