osx - CGEventCreateKeyboardEvent on Desktop vs MacBook -


Ola people,

Once again I want to drink from the pool of knowledge shared by people .

I wrote a small app for OSX that sends a major event to an app. I'm targeting OSX 10.5.x and new ones. However, the problem occurs when I also create for 10.6.x. Whenever I only send modifier keys, everything works fine; Alt, Command, Control and Shift.

The problem is that on two macbooks, incidents of modifier keys are cleared shortly, as soon as the testers touch the cursor or touchpad.

On the installed desktop, everything works just fine as it should be done on two different MacBooks, the problem is that the desktop has a standard 101 keyboard and a multi-button mouse attached is.
When a mouse is connected to a MacBook, two button icons are used with scrollable VL. However, the problem occurs when no external devices are connected and the touchpad is used.

What do I expect to happen is that the modifier key event is sent to the target application, the mouse cursor on the mouse cursor, mouse / touchpad on the keyboard, and / or the press button on the press keys to 'activate' With the modifier key below. Then, when they are finished, a key-up event is sent to the modifier key.

Here's how I am sending down the events below, Shift key for this example:

  Case ModKeyShiftDown: xEventSource = CGEventSourceCreate (kCGEventSourceStatePrivate); XTheCommand = CGEventCreateKeyboardEvent (xEventSource, KVK_shift, true); CGEventSetFlags (xTheCommand, kCGEventFlagMaskAlternate); CGEventPost (kCGHideventTap, xTheCommand); // CGEventPost (kCGSessionEventTap, xTheCommand); // CGEventPost (kCGAnnotated Session EventTap, xTheCommand); CFRelease (xTheCommand); CFRelease (xEventSource); break;  

I have used all three flags to create an Event Source (KCJentSourceSetSetPrivate, KCJentresourceStateCombinetationState and KCGEELSOSStreadHide SystemState).

I have also tried to create a keyboard event with the event source as the first parameter in the form of a null.

I have tried without incident and without a suitable flag on the incident.

I have tried various combinations of posting events; KCGHideventTap, kCG Session EventTap and kCGAnnotated Session EventTap.

For completeness, how I am sending an up event for the Shift key:

  Case ModKeyShiftUp: xEventSource = CGEventSourceCreate (kCGEventSourceStatePrivate); XTheCommand = CGEventCreateKeyboardEvent (xEventSource, kVK_Shift, Incorrect); CGEventSetFlags (xTheCommand, 0); CGEventPost (kCGHideventTap, xTheCommand); // CGEventPost (kCGSessionEventTap, xTheCommand); // CGEventPost (kCGAnnotated Session EventTap, xTheCommand); CFRelease (xTheCommand); CFRelease (xEventSource); break;  

When the testers trigger a modifier key below the event, they can see the cursor changes as expected, this shows me that this program is being processed by the target application is. However, as soon as they touch the mouse or touchpad, the cursor changes to a standard cursor and mouse events are processed, such that no modifier key event is active.

I know what is the problem in the way I am sending events, I would like to know whether the modified key to work is an alternative way of sending events.

Thanax

P>

Ola,

Interesting enough, the use of the ExpressionRF and the XUIElementPostkeyboard event works .

For whatever reason, sending the main event using the accessing object and the above method solves the problem for the test taker


Comments