-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash on MacOS 12.6 (M1) when pressing caps_lock #510
Comments
Thank you for your report. From what I have gathered, zsh report this error on unhandled signals, in this Perhaps adding some |
From other tests, and comparing it to the keyboard library, this happens because MacOS requires a delay when pressing caps lock. If I press it with the delay, pynput doesn’t crash.
… On 29-11-2022, at 15:32, moses-palmer - notifications at github.com ***@***.***> wrote:
Thank you for your report.
From what I have gathered, zsh report this error on unhandled signals, in this SIGTRAP. This should not happen in the library code nor in the Python runtime code. I suspect that the culprit is a native library, perhaps some part of pyobjc.
Perhaps adding some print statements in Listener._event_to_key <https://github.com/moses-palmer/pynput/blob/078491edf7025033c22a364ee76fb9e79db65fcc/lib/pynput/keyboard/_darwin.py#L311> would provide some hints as to where the error occurs?
—
Reply to this email directly, view it on GitHub <#510 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAUYXVOXCQH57P6CNYHM3D3WKZD3HANCNFSM6AAAAAARM5QAJU>.
You are receiving this because you authored the thread.
|
That's peculiar—a Would you mind posting a diff that fixes the code above? |
MacOS uses tap Capslock to switch InputMethod of non-English language, click it get a keycode 0xFF, I think it's a media-key stands for switching IME. Hold capslock triggers the true capslock keycode. Can be configured in: Settings > Keyboard > IME |
Just encountered this issue again. Did anybody find a solution to this, or the cause of the SIGTRAP? |
I do believe this problem is related to IME. For whatever reason, I found when I comment the line, the problem disappears. _EVENTS = (
Quartz.CGEventMaskBit(Quartz.kCGEventKeyDown) |
Quartz.CGEventMaskBit(Quartz.kCGEventKeyUp) |
Quartz.CGEventMaskBit(Quartz.kCGEventFlagsChanged)
| Quartz.CGEventMaskBit(Quartz.NSSystemDefined) # 👈 comment it if you do not want the media keys
) But Commenting this line will also lead to loss of the ability to listen to the system defined key. I am trying to use faulthandler to locate the line which triggered the unwanted exit, and it shows the following tracebacks.
which points to the line on my machine result = Quartz.CFRunLoopRunInMode(
Quartz.kCFRunLoopDefaultMode, 1, False) It seems like the problem has not happened inside python codebase. Just like moses-palmer said, It's related to pyobjc. |
Maybe because NSSystemDefined is deprecated? |
Based on the above suggestion, here is my temporary fix: removing
Hope someone can resolve this problem in future. |
Description
Keyboard listening on MacOS (M1 Pro) works and logs all keys. But it crashes after pressing Caps Lock
Platform and pynput version
macOS Monterey (12.6), M1 Pro. Pynput 1.7.6, Pyside6 6.4.0, Python 3.10. I'm also using a Latin American keyboard layout.
To Reproduce
https://github.com/alvaromunoz/pynput-macos-issues/blob/ba17e4b83f1eb239454d73ba96adf7f5fe71673b/caps_lock.py
OUTPUT:
The text was updated successfully, but these errors were encountered: