Using GraphicsServices.h/GSEvent as well as compiling CLI iPhone tools with Xcode

拜拜、爱过 提交于 2019-12-01 08:21:37

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!