之前看到有人再问如何实现模拟点击,这里分享一下我这里实现的模拟点击代码。(实际上是来求一两颗星的)
https://github.com/PugaTang/PTFakeTouch
之前我一直在用SIMULATETOUCH,不过这个只能越狱后使用,于是鼓捣了一个越狱非越狱都能方便用的静态库
使用说明:
工程编译后,生成的静态库直接导入要使用的工程。
USE CASE
Click a point at screen
NSInteger pointId = [PTFakeTouch fakeTouchId:[PTFakeTouch getAvailablePointId] AtPoint:CGPointMake(100,100) withTouchPhase:UITouchPhaseBegan];
[PTFakeTouch fakeTouchId:pointId AtPoint:CGPointMake(100,100) withTouchPhase:UITouchPhaseEnded];
Swipe screen
NSInteger pointId = [PTFakeTouch fakeTouchId:[PTFakeTouch getAvailablePointId] AtPoint:CGPointMake(100,100) withTouchPhase:UITouchPhaseBegan];
[PTFakeTouch fakeTouchId:pointId AtPoint:CGPointMake(300,300) withTouchPhase:UITouchPhaseMoved];
[PTFakeTouch fakeTouchId:pointId AtPoint:CGPointMake(300,300) withTouchPhase:UITouchPhaseEnded];
6 个赞
已加上。。。MARKDOWN不怎么会写,强行写了一下
sinsfk
(Shinobi)
5
不越狱的话,应该只能在本应用内模拟点击吧?还是也能全局模拟?
请问一下你这个库在越狱下的后台调用,能实现其他app的模拟点击嘛?
xiaozhuolinde-iPhone:/ root# ./test touch 50 50
2016-10-27 16:35:22.353 test[855:37501] [Enable]
2016-10-27 16:35:22.357 test[855:37501] [Enable]
2016-10-27 16:35:22.361 test[855:37501] PThelper initAtPoint setPhase 0
在ios8命令行调用你的接口,貌似没有成功,打印出了这些信息
- (void)load{
KW_ENABLE_CATEGORY(UITouch_KIFAdditions);
KW_ENABLE_CATEGORY(UIEvent_KIFAdditions);
touchAry = [[NSMutableArray alloc] init];
for (NSInteger i = 0; i<100; i++) {
UITouch *touch = [[UITouch alloc] initTouch];
[touch setPhaseAndUpdateTimestamp:UITouchPhaseEnded];
[touchAry addObject:touch];
}
}
你发的这份代码,貌似没有调用这个load,你的代码需要调用这个load方法吗
测试了下,你这个必须要注入其他app进程,才能使用,无法在后台适用于所有的app
Zhang
13
lolz
TOIDI NA SI YUG SHIT
today
(today)
14
导入静态库编译时报错 Undefined symbols for architecture x86_64:
“_IOHIDEventCreateDigitizerEvent”, referenced from:
Zhang
19
就是生成一个IOKt的Symbol Stub用来连接而已