GSEvent

From iPhone Development Wiki
Revision as of 22:42, 8 October 2013 by Eswick (talk | contribs) (Added instructions for sending GSEvents and cleaned up the article.)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.


GSEvent is a group of C functions located in GraphicsServices.framework that passes hardware events around the system. GSEvent is a core part of UIEvent, which is simply a wrapper around GSEvent.

GSEvents are sent using Mach messages. A basic event consists of the following information:

  • The type of event.
  • Location and time of the event.
  • Which process sent the event.
  • Which window should receive the event.

Event types

Some events can be used only for SpringBoard. They will usually become no-op when sent to non-SpringBoard apps. Note that some sensor events like the gyroscope and magnetometer are processed in CoreMotion by directly communicating with the HID subsystem, instead of via the slower GSEvent system.


type name
2000 Launch
2013 ?
2001 Another application finished launching
2002 ?
2012 Imminent process assertion expiration
2003 Resume
2014 Start running in task switcher and deactivate
2015 Stop running in task switcher and activate
2006 Handle test URL
2004 Did end resume animation
2005 Will begin suspend animation
2007 Suspend, events only
2008 Suspend
2009 Exit
2011 Suspend settings updated
12 Modifier changed
1012 Ringer off
1013 Ringer on
4001 Accessory key state changed
1022 Media key up
1023 Media key down
1014 Lock device
2010 Quit top application
500 Dump UI hierarchy
501 Dump screen contents
200 Process script
1100 Vibrate
1103 Set backlight level
23 Accelerometer event
50 Device orientation changed
24 Proximity state changed
6000 Urgent memory warning
1024 Status bar tapped
100 Reset idle timer and undim
60 App preference changed
1000 Menu button down
1001 Menu button up
1010 Lock button down
1011 Lock button up
1018 Headset button down
1019 Headset button up
1021 Headset availability changed
14 Hardware key down?
1020 Shake motion event
13 Simulator key down
22 Scroll wheel
3001 Hand event (i.e. touch-screen event)
10 Key down
11 Key up
1006 Volume Upper button down
1007 Volume Upper button up
1008 Volume Lower button down
1009 Volume Lower button up
1015 Status bar mouse down
1016 Status bar mouse dragged
1017 Status bar mouse up
1102 Set backlight factor
4000 Accessory availability changed
4002 ?
5000 Out-of-line data request
5001 Out-of-line data response

Sending a GSEvent

In order to send a GSEvent, one must first create a struct consisting of a GSEventRecord followed by the actual event data. Below is an example of creating and sending an orientation event to a specific process.

struct GSOrientationEvent {
        GSEventRecord record;
        GSDeviceOrientationInfo orientationInfo;
} event; //Declare the struct containing the GSEventRecord and the event info

event->record.type = kGSEventDeviceOrientationChanged; //Set the event record's type.
event->record.timestamp = mach_absolute_time(); //Set the timestamp.
event->record.senderPID = getpid();//Set the record's sender PID.
event->record.infoSize = sizeof(GSDeviceOrientationInfo); //Set the size of the event info (the size of the data following the GSEventRecord)

event->orientationInfo.orientation = UIInterfaceOrientationPortrait; //Set the orientation info to the orientation wanted.


SBApplication *safari = [[SBApplicationController sharedInstance] applicationWithDisplayIdentifier:@"com.apple.mobilesafari"];

GSSendEvent((GSEventRecord*)event, (mach_port_t)[safari eventPort]); //Send the GSEvent to Safari's event port.

Purple system event port

The "Purple system event port" is the Mach port that receives system events (e.g. kGSEventLockDevice). This port is registered whenever the --RegisterForSystemEvents flag is provided to a UIKit application, or it is the first application that registers the com.apple.eventpump service for bootstrap lookup. In the other words, these system events are directed to SpringBoard.

Header