2013-03-21 19 views
5

è possibile simulate touch events on iOS, ed è possibile ricevere le notifiche di larghezza varia di sistema quando in background utilizzando CTTelephonyCenterAddObserver e CFNotificationCenterAddObserver, ad esempio:iOS notifiche tocco di eventi (API private)

Devo ancora trovare un modo per ottenere le notifiche touch mentre in background però. Esiste un "evento tattile" che può essere utilizzato con CFNotificationCenterAddObserver, un diverso centro di notifica che può essere utilizzato o un approccio completamente diverso?

Sarei felice con informazioni di tocco di basso livello (ad esempio x, y coordinate e tipo di tocco), ma le informazioni di livello superiore (ad esempio tasto premuto, pulsante indietro premuto ecc.) Sarebbero ancora meglio!

+0

Forse questo potrebbe aiutare a http://stackoverflow.com/questions/8303235/is-it-possible-to-capture-touch-events-in-the-background- on-a-jailbroken-ios-dev. Effettua anche una ricerca per 'GSEvents' – Rog

risposta

14

È possibile utilizzare il materiale IOHID in IOKit per ottenere le coordinate x, y.

#include <IOHIDEventSystem.h> 

creare IOHIDEventSystemClient:

void *ioHIDEventSystem = IOHIDEventSystemClientCreate(kCFAllocatorDefault); 

registro callback:

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

annullare la registrazione di richiamata:

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

Inoltre, è possibile controllare questo: IOHIDEventSystemCreate on iOS6 failed. Spero che questo aiuti.

MODIFICA: Si prega di vedere il risultato dal registro. Testato su iPhone 4 e 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 
} 
} 
+0

Impressionante! Sto ricevendo gli eventi, ma i miei valori x, y sono enormi, ad esempio: 1050201600,000000, 1052667392,000000. Qualche consiglio? –

+0

Hai controllato xey prima di moltiplicare? Non sono davanti al mio Mac ora ma, per quanto mi ricordo, ho inserito x e y da%. Ad esempio, se si tocca l'angolo in alto a destra, x = 0,9 e y 0,1. – pt2121

+0

Sì, il numero enorme è la x, y senza moltiplicare. –

Problemi correlati