Event Labels: Modifying Results Using CGEventPost, kCGSessionEventTap, kCGAnnotatedSessionEventTap, CGEventTapPostEvent

I am having a difficult problem sending an event from an event. I use NSSystemDefined at kCGHIDEventTap, and then replace the event with a new one. The problem I am facing is that depending on how I post the event, this is only visible for some applications. My test applications are Opera, Firefox, Quicksilver, and Xcode. Here are some methods that I tried in my event callback, with the results. I expect action (the "correct answer") from each application; "system sound" means the sound "nothing to do with it."

  • Create a new event and return it from the callback. Opera: no answer / system signal, Firefox: no answer / system signal, Quicksilver: correct answer, Xcode: no answer / system signal

  • Create a new event, send a message to kCGSessionEventTap with CGEventPost, return null. Opera: no answer / system signal, Firefox: no answer / system signal, Quicksilver: correct answer, Xcode: no answer / system signal

  • Create a new event, send a message to kCGAnnotatedSessionEventTap with CGEventPost, return null. Opera: correct answer, Firefox: correct answer, Quicksilver: no answer / system signal, Xcode: no answer / system sound

  • Create a new event, publish with CGEventTapPostEvent, return null. Opera: no answer / system signal, Firefox: no answer / system signal, Quicksilver: correct answer, Xcode: no answer / system signal

  • Create a new event, send a message to kCGSessionEventTap using CGEventPost, and return the new event. Opera: no answer / system signal, Firefox: no answer / system signal, Quicksilver: correct answer, Xcode: no answer / system signal

  • Create a new event, send a message to kCGAnnotatedSessionEventTap using CGEventPost, and return the new event. Opera: correct answer and system sound, Firefox: correct answer and system sound, Quicksilver: correct answer and system sound, Xcode: no answer / double system sound

  • , CGEventTapPostEvent . Opera: / , Firefox: / , Quicksilver: , Xcode: /

(6) , , , , . , , . - - ? , ?

; .


: , :

CFMachPortRef eventTap;
eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, 0,CGEventMaskBit(NX_SYSDEFINED) | (1 << kCGEventKeyDown) | (1 << kCGEventKeyUp), myCGEventCallback, (void *)hidEventQueue);
+4
1

, . +[NSEvent keyEventWithType:location:modifierFlags:timestamp:windowNumber:context:characters:charactersIgnoringModifiers:isARepeat:keyCode:] NSEvent, -CGEvent. CGEventCreateKeyboardEvent, , CGEventCreateSourceFromEvent, . .

+4

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


All Articles