作为尝试学习为游戏制作机器人的尝试,我认为我可以使用一些自动光标移动来实现此目的...但是由于某种原因,每当我告诉程序保存位置并返回该位置时,似乎几乎要随机转到一个不同的位置,但是如果我问完成后该位置是什么,它表示该位置是正确的...我认为我做错了什么,有人可以告诉我什么吗?
from pynput.mouse import Button, Controller, Listener
import os
import time
import sys
def chestbutton():
mouse = Controller()
mouse.position = xx,yy
class Clicker():
def on_click(self, x, y, button, pressed):
global xx, yy
xx, yy = x, y
if not pressed:
return False
def Listen():
with Listener(on_click=Clicker().on_click) as listener:
listener.join()
def Listenstop():
with Listener(on_click=Clicker().on_click) as listener:
listener.stop()
xx, yy = 0, 0
os.system("cls||clear")
print("Please click on the upper most left area of the window")
Listen()
print("Your mouse position is: ",xx,yy)
variable23 = xx,yy
Listenstop()
time.sleep(2)
print("Mouse pointer movement test to: ", xx,yy)
mouse = Controller()
mouse.position = variable23
print(mouse.position)