Giter Site home page Giter Site logo

Typed keys about libuiohook HOT 7 CLOSED

kwhat avatar kwhat commented on May 18, 2024
Typed keys

from libuiohook.

Comments (7)

kwhat avatar kwhat commented on May 18, 2024

Looks like there are some serious issues with input events on OS X. I am not receiving events mouse events and experiencing deadlocks. You don't happen to know what commit started this behavior do you?

from libuiohook.

munsuri avatar munsuri commented on May 18, 2024

Using the latest master commit on this Macbook Pro 10.9.4 I don't have the issues you mention as long as I don't use CFRunLoopGetCurrent() instead of CFRunLoopGetMain() on the callback.

from libuiohook.

kwhat avatar kwhat commented on May 18, 2024

I found the source of the deadlock I am experiencing, but I am not sure it is cause of the problem you are describing.

First, the dead lock is on the hook_control_mutex and is caused by a race condition between hook_callback.c#L248 and
hook_thread.c#L51. You can probably get away with commenting out hook_thread.c#L51 for the time being. I will audit the program flow tonight and see if I can work out something better.

Now as far as the CFRunLoopGetCurrent() vs CFRunLoopGetMain() go, I am not sure what you are doing but maybe if I describe how the library works you can tell me how/why it is causing an issue. The library requires two runloops, one for the callback thread and the other is a Main RunLoop. The callback RunLoop (CFRunLoopGetCurrent) is pretty strait forward and is used to block the hooks pthread. The Main RunLoop (CFRunLoopGetMain) is required for the TIS functions in input_helper.c#L154 to prevent random thread safety issues like "TSMProcessRawKeyCode failed (-192)." Normally this wouldn't be a huge deal if we could use the LLVM blocks extension, but that is not available to this project for a number of reasons. So instead, I add my own observer to the main runlop in hook_callback.c#L177 and then signal and wait in hook_callback.c#L350 when a key typed event is required. The signal is picked back up in the hook_callback.c#L126 for processing and then a conditional is used to resume the hook thread. Do you have main RunLoop active? Did you stop the Main RunLoop started by the library?

from libuiohook.

munsuri avatar munsuri commented on May 18, 2024

Thanks for the clarifications.
I'll take that deadlock into account but as for now my test example doesn't reach hook_callback.c#L248 nor hook_thread.c#L51 (observer not notifying for a kCFRunLoopExit yet)

As for the other issue, it happens to me even with fresh check out of the master branch (didn't stop the main runloop, so it should be up and running). However, every time I type I get:

hook_event_proc [328]: Key 0X1E pressed. (0)
id=4,when=1413108888368,mask=0x0,keycode=30,rawcode=0x0
hook_event_proc [382]: Failed to signal RunLoop main!
hook_event_proc [403]: Key 0X1E released. (0)
id=5,when=1413108888376,mask=0x0,keycode=30,rawcode=0x0
hook_event_proc [328]: Key 0X1E pressed. (0)
id=4,when=1413108888776,mask=0x0,keycode=30,rawcode=0x0
hook_event_proc [382]: Failed to signal RunLoop main!
hook_event_proc [403]: Key 0X1E released. (0)
id=5,when=1413108888808,mask=0x0,keycode=30,rawcode=0x0
...
hook_event_proc [382]: Failed to signal RunLoop main!

So I checked that and I saw hook_callback.c#L335 returning NULL which according to the CFRunLoopCopyCurrentMode doc, indicates a not running loop and therefore never enters the key typed case. Then I played a bit by exchanging it for a CFRunLoopGetCurrent() but then it blocks there. I'll try to trace the main loop and see what happened to it.

from libuiohook.

kwhat avatar kwhat commented on May 18, 2024

Deadlocks are fixed in the trunk for Darwin and X11. Based on what you described, it sounds like you forgot to explicitly call CFRunLoopRun() from main. I'll play around with a little more and see if I can duplicate the issue.

from libuiohook.

munsuri avatar munsuri commented on May 18, 2024

Oh, yeah, perfect. Completely right. Porting the demo to only pthread's made me overlook that call. I will still try to move it to the darwin implementation. Thank you for pointing that out, for the deadlocks fix and this wonderful library.

from libuiohook.

kwhat avatar kwhat commented on May 18, 2024

Awesome! Thanks for the bug report and I am glad you are finding the library useful. I added a small note to the demo to avoid confusion.

from libuiohook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.