Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
541 views
in Technique[技术] by (71.8m points)

jailbreak - iOS touch event notifications (private API)

It's possible to simulate touch events on iOS, and you can receive various system wide notifications when in the background using CTTelephonyCenterAddObserver and CFNotificationCenterAddObserver, eg:

I've yet to find a way to get touch notifications while in the background though. Is there a "touch event" that can be used with CFNotificationCenterAddObserver, a different notification center that can be used, or a completely different approach?

I'd be happy with low level touch information (eg. x, y coordinates and touch type), but higher level information (eg. key pressed, back button pressed etc) would be even better!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use the IOHID stuff in IOKit to get the x, y coordinates.

#include <IOHIDEventSystem.h>

create IOHIDEventSystemClient:

void *ioHIDEventSystem = IOHIDEventSystemClientCreate(kCFAllocatorDefault);

register callback:

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

unregister callback:

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

callback:

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

Also, you can check this out: IOHIDEventSystemCreate on iOS6 failed. Hope this helps.

EDIT: Please see the result from the log. Tested on iPhone 4 and 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
}
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...