2013-03-21 16 views
5

O simulate touch events on iOS mümkün ve çeşitli sistem çapında bildirimleri alabilir zaman CTTelephonyCenterAddObserver ve CFNotificationCenterAddObserver, örneğin kullanarak arka planda:iOS dokunma olayı bildirimleri (özel API)

Arka plandayken dokunma bildirimleri almanın bir yolunu henüz bulamadım. CFNotificationCenterAddObserver ile kullanılabilecek farklı bir bildirim merkezi veya tamamen farklı bir yaklaşımla kullanılabilecek bir "dokunma etkinliği" var mı?

Düşük seviyeli dokunmatik bilgilerden (örn. X, y koordinatları ve temas tipi) memnun olurum, ancak daha yüksek seviye bilgileri (örn. Tuşa basma, geri düğmesine basma vb.) Daha iyi olurdu!

+0

Belki de bu size yardımcı olabilir http://stackoverflow.com/questions/8303235/is-it-possible-to-capture-touch-events-in-the-background- on-a-jailbreak-ios-dev. Ayrıca GSEvents ' – Rog

cevap

14

x, y koordinatlarını almak için IOHID öğelerini IOKit'da kullanabilirsiniz.

#include <IOHIDEventSystem.h> 

IOHIDEventSystemClient oluşturun:

void *ioHIDEventSystem = IOHIDEventSystemClientCreate(kCFAllocatorDefault); 

kayıt geri arama:

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

kaydını geri arama:

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

geri arama:

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

Ayrıca, bunu kontrol edebilirsiniz: IOHIDEventSystemCreate on iOS6 failed. Bu yardımcı olur umarım.

DÜZENLEME: Lütfen kütükten sonuca bakın. iPhone 4 üzerinde test edilmiştir ve 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

Awesome için bir arama yapın! Olayları alıyorum ama x, y değerlerim çok büyük, örneğin: 1050201600.000000, 1052667392.000000. Herhangi bir ipucu? –

+0

Çarpmadan önce x ve y'yi kontrol ettiniz mi? Şu an Mac'imin önünde değilim ama hatırladığım kadarıyla, x ve y değerini% 'den aldım. Örneğin, sağ üst köşeye dokunduğunuzda, x = 0,9 ve y 0,1. – pt2121

+0

Evet, büyük sayı, çarpmadan x, y'dir. –

İlgili konular