Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate a tap, is possible?

I know that is possible to intercept a tap on a screen, but I want to know if is it possible to simulate a tap in a point of screen (with x and y coordinates). Thanks

like image 794
Andrea Avatar asked Mar 01 '11 22:03

Andrea


2 Answers

UITouch *touch = [[UITouch alloc] initInView:view];
UIEvent *eventDown = [[UIEvent alloc] initWithTouch:touch];

[touch.view touchesBegan:[eventDown allTouches] withEvent:eventDown];

[touch setPhase:UITouchPhaseEnded];
UIEvent *eventUp = [[UIEvent alloc] initWithTouch:touch];

[touch.view touchesEnded:[eventUp allTouches] withEvent:eventUp];

[eventDown release];
[eventUp release];
[touch release];

from here http://cocoawithlove.com/2008/10/synthesizing-touch-event-on-iphone.html

like image 98
madmik3 Avatar answered Sep 29 '22 11:09

madmik3


If it is a non-jailbroken device, check this: PTFakeTouch (worked for ios 11). It only works inside your applications. Since you are using private APIs, you might get rejected from the App Store.

If you want to simulate system-wide touch events, you have to jailbreak your device.

Check these links for jailbroken devices:

Simulate Touch Event on iOS - jailbroken - iOS13+

Is possible to simulate touch event using an external keyboard on ios jailbroken?

like image 27
Jason Z Avatar answered Sep 29 '22 10:09

Jason Z