Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What is the event path from user to application?




On Oct 16, 2005, at 1:00 PM, Eric Schlegel wrote:

Here's a quick overview:

- user presses a keystroke
- the HID Manager portion of IOKit handles an interrupt, reads the keyboard data, and notifies the Window Server
- the Window Server is a separate process that is part of the CoreGraphics framework. It routes user input events to the appropriate process (the process that currently has keyboard focus)
- the Window Server gets the event and signals a mach port for the focused process
- the focused process's run loop wakes up because of the signal on its mach port and reads the input event from the Window Server



I was trying to find more information about how these two steps worked, but couldn't find anything. Is it possible for an application other than the Window Server to get a copy of that port, and if so, how is it used?


- the focused process converts the input event into a Carbon event (note that this is true for Cocoa apps as well, since the Cocoa event system uses Carbon events for its lowest-level event receipt) and posts it into the Carbon event queue

Okay, so all applications receive low level Carbon events? These would be of the kEventRawKey... type, correct? And then does the standard window handler or whatever convert those raw key events into higher level events for the application to handle? Is an event posted to the application's main event queue indistinguishable from an event sent to the application by the Window Server, and will that work for Cocoa applications? If so, then the mach_inject method is still a possibility.


- the focused process pulls the next event from the Carbon event queue and returns it to the app as a Carbon Event, EventRecord, or NSEvent, depending on the type of app

If you need to insert keyboard events and mouse events into another application, most likely the best way to do this will be to use the APIs in CoreGraphics/CGRemoteOperation.h, which are designed for this purpose.


My concern with doing it that way is that I only want the application I specifically target to receive these events. If I use the remote operation APIs, then it looks like I'll need to find some way to keep track of what the focussed application is and only send events when my target is focussed. Alternatively I suppose my testing program could force the target application to take focus and then I'd have to not touch anything and hope no other programs jump to the foreground while the testing is running. That seems fragile, and I don't know if I can make another specific application take the focus. I also worry that there might be a race condition where I'd check if my target is focussed, then focus would change to a different application before I sent the event, and the wrong application would receive my synthetic event.


Any further ideas or advice?

-Greg

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden
References: 
 >What is the event path from user to application? (From: Gregory Cooksey <email@hidden>)
 >Re: What is the event path from user to application? (From: Eric Schlegel <email@hidden>)



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

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.