python模拟点击在ios中实现的实例讲解

来自:网络
时间:2021-01-13
阅读:

我们都知道因为操作系统的不同,很多游戏区分为安卓和苹果两个版本。那么之前学会python模拟点击的小伙伴开始担心,如果手机是ios版本那还能使用吗?这个问题小编进行了测试,小伙伴们完全不用忧虑ios版本,因为经过测试的结果是可以使用的。具体在ios中模拟点击使用的细节大家也可以看看了解一下。

代码示例

Python Version
import socket
import time
# event types
TOUCH_UP = 0
TOUCH_DOWN = 1
TOUCH_MOVE = 2
SET_SCREEN_SIZE = 9
# 这个函数直接复制粘贴到你的代码就好
def formatSocketData(type, index, x, y):
 return '{}{:02d}{:05d}{:05d}'.format(type, index, int(x*10), int(y*10))
s = socket.socket()
s.connect(("127.0.0.1", 6000)) # 连接手机 把127.0.0.1换成你手机的ip地址
s.send(("1"+formatSocketData(SET_SCREEN_SIZE, 0, 2732, 2048)).encode()) # 首先设置屏幕大小(后续版本会实现自动获取)
time.sleep(1) # 休息一秒
s.send(("1"+formatSocketData(TOUCH_DOWN, 7, 300, 400)).encode()) # 点击屏幕上的 (300, 400)
# 重要: 注意在最前面的“1”。这个表明了只有一个event要处理。这个“1”不可以被省略
s.close()

实际上,一行代码就实现了iOS点击模拟

s.send(("1"+formatSocketData(TOUCH_DOWN, 7, 300, 400)).encode())

手指移动模拟

s.send(("1"+formatSocketData(TOUCH_MOVE, 7, 800, 400)).encode()) # tell the tweak to move our finger "7" to (800, 400)

抬起手指模拟

s.send(("1"+formatSocketData(TOUCH_UP, 7, 800, 400)).encode()) # tell the tweak to touch up our finger "7" at (800, 400)
返回顶部
顶部