Open 0x11-dev opened 6 months ago
To resolve this, we need to make a copy of the CGEventRef with CGEventRef eventCopy = CGEventCreateCopy(event); instead of using a getter from the main thread.
I am probably never going to be able to reproduce this issue so I will need to rely on you to both provide a solution and test that solution to ensure it works. When you say I need to make a copy of the event, are we talking about the event_ref
passed to the function and assigned tis_keycode_message->event = event_ref;
? Let me know and I can put the fix in.
We definitely cant comment out those two lines and expect key typed events to work on macOS. It's running into a deadlock because its trying to run that code on the primary runloop and obviously these other languages are using that runloop for something else...
Did either of the other solutions mentioned in this ticket work? We should probably figure out why dispatch_sync_f is blocking indefinitely for the main run loop. I suspect node, and probably dart are doing something that blocks the execution on this thread and unfortunately Apple's TIS functions can only be run from that thread.
We definitely cant comment out those two lines and expect key typed events to work on macOS. It's running into a deadlock because its trying to run that code on the primary runloop and obviously these other languages are using that runloop for something else...
Did either of the other solutions mentioned in this ticket work? We should probably figure out why dispatch_sync_f is blocking indefinitely for the main run loop. I suspect node, and probably dart are doing something that blocks the execution on this thread and unfortunately Apple's TIS functions can only be run from that thread.
I'll look into trying out the other solutions now, but for context, I'm using C++ and I found this issue to still arise in a sandbox like environment. However, since the C demo is working, I'll have to re-check my implementation to ensure it's not an issue on my end.
I have built the dart wrapper for this library, And by using that solution i mentioned above it works fine in Dart as well as Flutter https://github.com/rohitsangwan01/uiohook_dart/tree/main/uiohook_dart This happens on mac only
@kwhat I rewrote my implementation of libuiohook and it seems to run perfectly now, tried to keep it quite basic and it seems to have done the trick so for me I have no more issues (I think I must've been doing something dodgy with threading).
However, and I'm happy to start another issue if need be, I want to ask if you have had any issues regarding debugging libuiohook on Windows? To reproduce I'm using Visual Studio 2022 on Windows and attached the debugger to the demo_hook example and have hit 'break all' during libuiohook's event loop and it has brought my computer to a standstill. Is this something you've witnessed at all?
I rewrote my implementation of libuiohook and it seems to run perfectly now, tried to keep it quite basic and it seems to have done the trick so for me I have no more issues (I think I must've been doing something dodgy with threading).
That's good to hear. I have tried to keep as much of the threading out of this library as possible for a number of reasons and as a result of that the event callback always executes on the thread you started to hook from. If you need to do work on the callback, it's probably best to copy the memory to another thread and do the work there. The only other threading happens is on macOS because the TIS function calls have to happen on the main runloop for undocumented reasons from Apple.
There are a number of upstream bugs about debugging for windows: #412 #264 #232 and #137. One of these has a possible solution in it where on Windows a debugger attachment can be detected and the hook could be stopped. The same problem should exist on macOS in theory and will also present itself on Linux/Unix as soon as I get the Wayland code in place. I have not tested the proposed solution but if you want to give it a try please open a new bug and we can start with Windows.
dispatch_sync_f(dispatch_get_main_queue(), XX, XX)
in here line 280 will make a deadlock situation. To resolve this, we need to make a copy of the CGEventRef withCGEventRef eventCopy = CGEventCreateCopy(event);
instead of using a getter from the main thread.related issue: #https://github.com/SnosMe/uiohook-napi/issues/23#issuecomment-2016526280
The call graph is as follows: