How to determine the key or key for caplock key in OS X?

I have a problem with OS X detecting keystrokes. I need to detect a key down and a key to unlock a key or key whenever a keyboard key is pressed. This is pretty straight forward if you intercept the application event processing chain using [ NSEvent addLocalMonitorForEventsMatchingMask: handler: ] . This allows you to intercept and modify NSEvent for various types of events, including NSKeyUp and NSKeyDown for regular print keys, as well as NSFlagsChanged , which can be used to detect shift, ctrl, alt and CMD. In fact, since the modifier flags change both up and down for the shift, ctrl, alt and cmd NSFlagsChanged , NSFlagsChanged can be used as a key and key event for these keys by checking [NSEvent modifierFlags] along with [NSEvent keyCode] .

Kapslok is different, however. Since the caplock modifier really only acts on the down key when you press capslock, you only get NSFlagsChanged with a click on the button, not when it is released. Both NSKeyUp and NSKeyDown not highlighted using modifier keys such as caplock and shift and ctrl, etc.

Can someone suggest a way, and maybe even a lower-level interface, for receiving events with closing the lock? Should I resort to using kqueues or something else?

+4
source share
1 answer

IOHIDLib seems to be the only way to do this. I (or actually on the comrade’s side) used the IOHIDManager to set up an event callback that successfully intercepted the key lock and keyboard close events.

It's terrible that this is completely outside the Cocoa / CoreFoundation event dispatch mechanism, which means you get events even if your application is out of focus. You ultimately have to do a lot of window management and focus detection yourself.

But it works.

+2
source

Source: https://habr.com/ru/post/1435560/


All Articles