在我取消最小化游戏之前,该代码可以完美运行,没有错误。经过多次尝试找出 SetCursorPos 不起作用的原因后,我了解到它的电源线没有问题,但是当它打开时它拒绝移动到该位置游戏窗口。到目前为止的代码是:
from PIL import ImageGrab
import os
import time
import win32con , win32api
x_pad = 2
y_pad = 27
def start():
#location of first menu
mousePos((682, 519))
leftClick()
time.sleep(.1)
leftClick()
time.sleep(.5)
#location of second menu
mousePos((1208, 528))
leftClick()
time.sleep(.5)
#location of third menu
mousePos((921, 479))
leftClick()
time.sleep(.5)
#location of fourth menu
mousePos((651, 350))
leftClick()
time.sleep(.5)
def screenGrab():
box = (x_pad+1,y_pad+1,x_pad+1362,y_pad+770)
im = ImageGrab.grab(box)
im.save(os.getcwd() + '\\full_snap__' + str(int(time.time())) +
'.png', 'PNG')
def mousePos(cord):
win32api.SetCursorPos((x_pad + cord[0], y_pad + cord[1]))
def get_cords():
x,y = win32api.GetCursorPos()
x = x - x_pad
y = y - y_pad
print x,y
def leftClick():
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
time.sleep(.1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
print "Click."
def main():
pass
if __name__ == "__MAIN__":
main()
当我运行 start() 我得到这个:
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
>>> start()
'Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
start()
File "C:\Users\User\Desktop\py\game.py", line 12, in start
mousePos((682, 519))
File "C:\Users\User\Desktop\py\game.py", line 42, in mousePos
win32api.SetCursorPos((x_pad + cord[0], y_pad + cord[1]))
error: (0, 'SetCursorPos', 'No error message is available')'
>>>
我不知道为什么会发生这种情况,我已经尝试了这个网站的许多解决方案,这可能是游戏吗?我想知道是游戏是错误的原因还是我错过了什么,以及是否有可能的解决方案。