Fix kCGEventTapDisabledByTimeout to not break event tap on Mac#184
Conversation
|
@kwhat I'd appreciate a review whenever you're free! Let me know if you have any feedback |
|
Hi @kwhat, another user of libuiohook via uiohook-napi here. It would be helpful to know if you are open to merging this fix or if we should aim to incorporate it downstream as a patch. The Mac issue it fixes is pretty severe, leading to a silent failure of the hook, and sometimes a crash. |
|
Hey, sorry for the delay. I've been pretty deep into the Wayland port on the Linux side for the past few weeks. I am definitely going to merge it, the question is should it go in 1.2 or 1.3. Windows needs a similar fix but its going to break other things so I wasn't planning on putting it in until 1.3. I guess if you are waiting on this fix, we can merge it in tonight and I can do the Windows side in 1.3 later. Let me know and thanks again for the fix. |
|
Thanks for considering this. @hsource was gracious enough to submit this PR both here and as a patch to uiohook-napi. So if it's not practical to merge here we can go the patch route, but merging here seems cleaner 😃. FWIW I've never seen any similar issue on Windows, and I use it on Windows a lot. |
|
See #171 for the windows issues. |
Motivation
Fixes jnativehook issue 225
I was working on porting to Mac https://github.com/SnosMe/awakened-poe-trade, which depends on https://github.com/SnosMe/uiohook-napi, which depends on this library.
I noticed that after the terminal logs "hook_event_proc [1013]: CGEventTap timeout!", keyboard events would stop working.
Debugging
I could trigger this fairly consistently in awakened-poe-trade by clicking a lot and closing a video game that awakened-poe-trade is built to be used with
Fix and testing
Currently, the library tries to fix this error by fully reinitializing the event tap. This doesn't seem to work very well. I tried forcing the reinitialization, and events always stopped as soon as I tried to go through the reinitialization loop.
The original Stackoverflow thread linked in the comment (http://stackoverflow.com/questions/2969110/cgeventtapcreate-breaks-down-mysteriously-with-key-down-events#2971217) recommends just using
CGEventTapEnableI just did that, and it seems to work! Even after getting a "hook_event_proc [1013]: CGEventTap timeout!" message, my mouse/keyboard events still worked.