如何将pyautogui.position()[0]
(X坐标)与前一个x位置进行比较,以确定鼠标光标是向左还是向右?我是否需要使用多线程,因为每次调用pyautogui
方法?
谢谢!
答案 0 :(得分:0)
编辑(添加说明): 您检查x坐标相差0.1秒,以判断鼠标指针的移动方向。要并行更新鼠标指针的移动方向,可以对该函数进行穿线。
import _thread
import pyautogui
import time
def left_or_right():
while True:
x1 = pyautogui.position()[0]
time.sleep(0.1)
x2 = pyautogui.position()[0]
diff = x2 - x1
if diff > 0:
print('going right')
elif diff < 0:
print('going left')
else:
print('not moving')
_thread.start_new_thread(left_or_right, ())