首先,声明 GSEvent 并发送它的最简单方法是什么?
这取决于 GSEvent 的类型。有些事件具有方便的功能,可以一步创建和发送,例如GSEventLockDevice()
。但HID事件(触摸、按键等)不具备这些简单的功能。原因很可能是因为GSEventLockDevice()
等将被发送from将应用程序发送到 SpringBoard,但发送 HID 事件fromSpringBoard 到应用程序。因此,只有SpringBoard团队需要知道如何构造一个复杂的GSEvent。
无论如何,要创建 HID 事件(例如加速度计事件),您不需要创建 GSEvent。只需使用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);
但什么是“应用程序端口”?不幸的是没有函数可以实现这一点。从 3.1 开始,mach 端口的名称与其捆绑包 ID 相同,因此您可以使用:
mach_port_t thePortOfApp = GSCopyPurpleNamedPort("com.unknown.appBundleID");
...
mach_port_deallocate(mach_task_self(), thePortOfApp); // remember to release the port.
另外,如果我希望这个实用程序能够像 Springboard 一样操作所有应用程序,我是否必须编写或执行任何特殊操作?
据我所知,没有。
对于另外两个问题,您可能应该将它们分成单独的问题。