Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Big problems posting keyboard events with CGEventPost in Snow Leopard
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Big problems posting keyboard events with CGEventPost in Snow Leopard



I don't mean to be flooding this list or anything, but I think I might
have finally solved my problem, and my solution might be useful for
anyone else who encounters the same problem down the road.

I noticed that the first event I attempt to post never gets lost or
posted out of order, so what I did was set up a thread-safe queue
(just using MPQueue) where I'd add events to it in the order I wanted
them posted.  I'd remove the first event in the queue, give it a
special identifier in its kCGEventSourceUserData property, and then
use CGEventPost to post it to kCGSessionEventTap.

Then, in an event tap at the user session level, I'd have it check for
events with that specific identifier in the user data, and upon
finding it, post it using CGEventTapPost and passing in the tap's
CGEventTapProxy structure.  Afterwards, I'd grab all the remaining
events from the queue and post them in order using CGEventTapPost, all
in the event tap.  That seems to do the trick so far - none of the
events are posted out of order, or dropped.  Hopefully that'll keep
up, and I won't have to try yet another solution.

- Brian


On Wed, Oct 28, 2009 at 4:51 PM, Brian Kendall <email@hidden> wrote:
>
> On Wed, Oct 28, 2009 at 3:24 PM, Brian Kendall <email@hidden> wrote:
> > Okay, I think I managed to find the cause of my problem.  It turns out
> > that it didn't have to do with the method I was using to post keyboard
> > events, but rather a stupid programming error in my code that caused
> > my function to intentionally post the kCGEventFlagsChanged events to a
> > single application while posting the keystrokes to kCGSessionEventTap.
> >  Obviously that would cause problems.  Apparently something about the
> > events subsystem in OS X 10.5.X didn't cause this error to be an
> > issue.  But I've fixed it and things seem to be working normally again
> > in Snow Leopard.  Hopefully I've fixed it for good.
> >
> > - Brian
>
> Nevermind - I spoke too soon.  Since fixing that last error, I can
> observe all the events I want being posted to kCGSessionEventTap, but
> they still occasionally (maybe one out of twenty) end up in the wrong
> order, oftentimes with the kCGEventKeyDown being posted last,
> resulting in a "stuck" key.
>
> I tried taking the suggestion of Bill Cheeseman who responded to one
> of my earlier emails by not posting kCGEventFlagsChanged events
> anymore - just the key down and key up events.  They still end up in
> the wrong order, though, so that doesn't seem to have any effect.
>
> However, I haven't observed any dropped events any longer, so at least
> that seems to be working normally.
>
> - Brian
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartz-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Big problems posting keyboard events with CGEventPost in Snow Leopard (From: Brian Kendall <email@hidden>)
 >Re: Big problems posting keyboard events with CGEventPost in Snow Leopard (From: Brian Kendall <email@hidden>)
 >Re: Big problems posting keyboard events with CGEventPost in Snow Leopard (From: Brian Kendall <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.