Fix kCGEventTapDisabledByTimeout to not break event tap on Mac #184
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.