今天我写了个压枪程序,原理是按了鼠标的x1,然后调用函数,进行压枪,在进行到第三十发的时候,就结束函数。
可是并没有按我想的那样去做,而是要一直按着鼠标左键。然后疯狂按鼠标的x1键,才能完成压枪
但也不是压枪,这种操作会很卡
大家可以去试试,看卡不卡
一直想了很多方法,例如有个错误说应为int但是实际是float
提示错误代码如下
ak_recoil = [[float(i)for i in x] for x in ak_recoil]
然后我将他改成了
ak_recoil = [[int(float(i)) for i in x] for x in ak_recoil]
但是效果还是那样
代码如下
import csv
import time
from threading import Thread
import pynput.mouse
def yq():
ak = csv.reader(open('./csgo_dd/ak47.csv', encoding='utf-8'))
ak_yq = []
for i in ak:
ak_yq.append(i)
ak_yq[0][0] = '0'
ak_yq = [[float(i) for i in x] for x in ak_yq]
print(ak_yq)
k = -1
mouse = pynput.mouse.Controller()
flag = 0
yq_mode = False
with pynput.mouse.Events() as events:
for event in events:
if isinstance(event, pynput.mouse.Events.Click):
if event.button == event.button.left:
if event.pressed:
flag = 1
else:
flag = 0
if event.button == event.button.x2 and event.pressed:
yq_mode = not yq_mode
print('yq_mode', 'on' if yq_mode else 'off')
if flag and yq_mode:
i = 0
a = next(events)
while True:
mouse.move(ak_yq[i][0] * k, ak_yq[i][1] * k)
i += 1
if i == 30:
break
if a is not None and isinstance(a, pynput.mouse.Events.Click) and a.button == a.button.left and not a.pressed:
break
a = next(events)
while a is not None and not isinstance(a, pynput.mouse.Events.Click):
a = next(events)
time.sleep(ak_yq[i][2] / 1000)
flag = 0
y = Thread(target=yq)
y.start()
y.join()
此游戏为csgo
想尝试的小伙伴请关闭原生输入
pynput.mouse.Events()
这必须要鼠标在你的py窗体范围内才起作用,你把窗体最小化了,鼠标跑别的进程窗体里了,它就不起作用了呀
你需要调用系统的API,读取全局的鼠标事件,而不是鼠标在你自身的进程里引发的事件