iOS touch事件通知(私人API)

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

  • IOS越狱如何拦截短信/短信
  • 如何检测iPhone上的屏幕locking/解锁事件?

我还没有find一种方法来获得触摸通知,而在后台虽然。 是否有可以与CFNotificationCenterAddObserver一起使用的“触摸事件”,可以使用的不同通知中心,还是完全不同的方法?

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

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

 #include <IOHIDEventSystem.h> 

创buildIOHIDEventSystemClient:

 void *ioHIDEventSystem = IOHIDEventSystemClientCreate(kCFAllocatorDefault); 

注册callback:

 IOHIDEventSystemClientScheduleWithRunLoop(ioHIDEventSystem, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); IOHIDEventSystemClientRegisterEventCallback(ioHIDEventSystem, handle_event, NULL, NULL); 

取消注册callback:

 IOHIDEventSystemClientUnregisterEventCallback(ioHIDEventSystem, handle_event, NULL, NULL); IOHIDEventSystemClientUnscheduleWithRunLoop(ioHIDEventSystem, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); 

回电话:

 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) ; } } 

此外,您可以检查了这一点: IOHIDEventSystemCreate在iOS6失败 。 希望这可以帮助。

编辑:请看日志的结果。 testingiPhone 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 } }