I sent this to KennyTM (has all the private framework headers on GitHub) but I figured I'd ask here too just in case someone has some good ideas or any way to help me out.
I'm trying to write a command line utility that sends GSEvents to operate the keyboard, touch/drag elements onscreen, and operate hardware buttons (volume, home, sleep, etc.)
I grabbed the MouseSupport code and tried to look through it, but I couldn't find the easiest way to send GSEvents. I'm hoping someone here can help me.
First, what's the simplest way to declare a GSEvent and send it? I looked at the iPhone development wiki, but the documentation was very vague. I understand that there's a purple event port (?) that I have to send these events to, but I don't understand how to do that. Could someone offer examples for, say, touching at a coordinate, typing a certain key, or pressing a hardware button?
Also, do I have to write or do anything special if I want this utility to operate all applications as well as Springboard? I don't know if this is a special case because I want it at the OS level. Ideally, I would SSH into the phone, start the program, and it would send GSEvents that would be handled by whatever application was open.
As far as compiling this code, is there any way to do so under Xcode? I don't know what sort of project template I should use (if any) and this is throwing me off. I don't need "build and go" support, I'm more than happy to scp the program over to the phone. I understand that compiling the code is also feasible on the phone. I have all of the headers from the SDK on my phone along with iphone-gcc, but when compiling some test programs I still get errors about not finding mach headers and CoreFoundation. Is there an easier way to do this?
Lastly, are there other guides or pieces of literature that anyone can point me towards for learning more about this? I'm excited to get into open iPhone development (I have experience with the official SDK, but I want to go deeper).
Thanks for any and all help people can offer!
First, what's the simplest way to declare a GSEvent and send it?
It depends on the type of the GSEvent. Some events have convenient functions that can be created and sent in one step, e.g. GSEventLockDevice()
. But HID events (touches, key presses, etc.) do not have these simple functions. The reason is likely because GSEventLockDevice()
etc are to be sent from the app to SpringBoard, but HID events are sent from SpringBoard to an app. Therefore, only the SpringBoard team needs to know how to construct a complicated GSEvent.
Anyway, to create a HID event (e.g. accelerometer event) you don't need to create a GSEvent. Just use GSSendEvent()
:
// (not tested.)
GSAccelerometerInfo accel = {0.0f, 0.0f, 1.0f};
GSEventRecord header;
memset(&header, 0, sizeof(header));
header.type = kGSEventAccelerate;
header.infoSize = sizeof(accel);
header.timestamp = mach_absolute_time();
// fill in other members.
struct {
GSEventRecord record;
GSAccelerometerInfo info;
} record = {header, accel};
// ... see below ...
GSSendEvent(&record, thePortOfApp);
But what is "the port of app"? Unfortunately there's no function to get that. As of 3.1, the name of the mach port is same as its bundle ID, so you could use:
mach_port_t thePortOfApp = GSCopyPurpleNamedPort("com.unknown.appBundleID");
...
mach_port_deallocate(mach_task_self(), thePortOfApp); // remember to release the port.
Also, do I have to write or do anything special if I want this utility to operate all applications as well as Springboard?
As far as I know, no.
For the other two, probably you should split them into individual questions.
来源:https://stackoverflow.com/questions/3017367/using-graphicsservices-h-gsevent-as-well-as-compiling-cli-iphone-tools-with-xcod