Skip to content
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

Fix kCGEventTapDisabledByTimeout to not break event tap on Mac #184

Merged
merged 1 commit into from
Jan 3, 2024

Conversation

hsource
Copy link
Contributor

@hsource hsource commented Dec 7, 2023

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 CGEventTapEnable

I 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.

@hsource
Copy link
Contributor Author

hsource commented Dec 8, 2023

@kwhat I'd appreciate a review whenever you're free! Let me know if you have any feedback

@marcelblum
Copy link

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.

@kwhat
Copy link
Owner

kwhat commented Jan 3, 2024

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.

@marcelblum
Copy link

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.

@kwhat
Copy link
Owner

kwhat commented Jan 3, 2024

See #171 for the windows issues.

@kwhat kwhat merged commit f259ff3 into kwhat:1.2 Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Library hangs on MacOS 10.13.5
3 participants