Open perroboc opened 1 year ago
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
would provide some hints as to where the error occurs?
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 https://github.com/moses-palmer/pynput/issues/510#issuecomment-1331114871, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUYXVOXCQH57P6CNYHM3D3WKZD3HANCNFSM6AAAAAARM5QAJU. You are receiving this because you authored the thread.
That's peculiar—a SIGTRAP
because of a missing delay?
Would you mind posting a diff that fixes the code above?
I’d LOVE to, but I haven’t found a fix yet. Further tests show that even holding the button does NOT fix the issue, sorry.
Here's a video showing the difference the behavior when holding the key or not:
Is there any way to read the SIGTRAP dumps?
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.
Python error: Aborted
Thread 0x0000000175903000 (most recent call first):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pynput/_util/darwin.py", line 215 in _run
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pynput/keyboard/_darwin.py", line 253 in _run
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pynput/_util/__init__.py", line 210 in run
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 1016 in _bootstrap_inner
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 973 in _bootstrap
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?
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: