-->

iOS的触摸事件通知(私有API)(iOS touch event notifications (p

2019-07-22 05:40发布

这是可能的模拟iOS上的触摸事件 ,并且可以接收各种系统范围的通知时使用CTTelephonyCenterAddObserver和CFNotificationCenterAddObserver,如背景:

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

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

我很高兴与低级别的触摸信息(例如,X,Y坐标和触摸式),但更高层次的信息(例如,键按下,返回键按下等)将更加美好!

Answer 1:

您可以使用IOHID东西,在由于IOKit得到x,y坐标。

#include <IOHIDEventSystem.h>

创建IOHIDEventSystemClient:

void *ioHIDEventSystem = IOHIDEventSystemClientCreate(kCFAllocatorDefault);

注册回调:

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

注销回调:

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的失败 。 希望这可以帮助。

编辑:请参阅从日志结果。 测试在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
}
}


文章来源: iOS touch event notifications (private API)