iOS触摸事件通知(私有API)

Ben*_*ing 6 jailbreak iphone-privateapi ios

可以在iOS模拟触摸事件,并且您可以在后台使用CTTelephonyCenterAddObserver和CFNotificationCenterAddObserver接收各种系统范围的通知,例如:

我还没有找到一种在后台获取触摸通知的方法.是否有可以与CFNotificationCenterAddObserver一起使用的"触摸事件",可以使用的不同通知中心,还是完全不同的方法?

我会对低级别的触摸信息(例如x,y坐标和触摸类型)感到满意,但更高级别的信息(例如按下按键,按下后退按钮等)会更好!

pt2*_*121 15

您可以使用IOKit中的IOHID内容来获取x,y坐标.

#include <IOHIDEventSystem.h>
Run Code Online (Sandbox Code Playgroud)

创建IOHIDEventSystemClient:

void *ioHIDEventSystem = IOHIDEventSystemClientCreate(kCFAllocatorDefault);
Run Code Online (Sandbox Code Playgroud)

注册回调:

IOHIDEventSystemClientScheduleWithRunLoop(ioHIDEventSystem, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
IOHIDEventSystemClientRegisterEventCallback(ioHIDEventSystem, handle_event, NULL, NULL);
Run Code Online (Sandbox Code Playgroud)

取消注册回调:

IOHIDEventSystemClientUnregisterEventCallback(ioHIDEventSystem, handle_event, NULL, NULL);
IOHIDEventSystemClientUnscheduleWithRunLoop(ioHIDEventSystem, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
Run Code Online (Sandbox Code Playgroud)

打回来:

void handle_event (void* target, void* refcon, IOHIDServiceRef service, IOHIDEventRef event) {
   if (IOHIDEventGetType(event)==kIOHIDEventTypeDigitizer){
       IOHIDFloat x=IOHIDEventGetFloatValue(event, (IOHIDEventField)kIOHIDEventFieldDigitizerX);
       IOHIDFloat y=IOHIDEventGetFloatValue(event, (IOHIDEventField)kIOHIDEventFieldDigitizerY);
       int width = [[UIScreen mainScreen] bounds].size.width;
       int height = [[UIScreen mainScreen] bounds].size.height;
       NSLog(@"click : %f, %f", x*width, y*height) ;
   }
}
Run Code Online (Sandbox Code Playgroud)

此外,您可以检查一下: iOS6上的IOHIDEventSystemCreate失败.希望这可以帮助.

编辑:请查看日志中的结果.在iPhone 4和5上测试过.

void handle_event (void* target, void* refcon, IOHIDServiceRef service, IOHIDEventRef event) {
    NSLog(@"handle_event : %d", IOHIDEventGetType(event));
if (IOHIDEventGetType(event)==kIOHIDEventTypeDigitizer){
    IOHIDFloat x=IOHIDEventGetFloatValue(event, (IOHIDEventField)kIOHIDEventFieldDigitizerX);
    IOHIDFloat y=IOHIDEventGetFloatValue(event, (IOHIDEventField)kIOHIDEventFieldDigitizerY);
    NSLog(@" x %f : y %f", x, y);
//2013-03-28 10:02:52.169 MyIOKit[143:907] handle_event : 11
//2013-03-28 10:02:52.182 MyIOKit[143:907]  x 0.766754 : y 0.555023
}
}
Run Code Online (Sandbox Code Playgroud)