帮助我卡住了。我想为" cookie clicker 2"制作一个自动点击器。你懂。我喜欢饼干,我想要它们很快:P ..... soooo我写了这个剧本:
import win32api, win32con, win32gui
import random
import time
import os
menu = []
mouseClick = []
stop = []
x = []
y = []
def menu():
x = input("Geef de X as op >> ")
y = input("Geef de Y as op >> ")
mouseClick()
def mouseClick():
win32api.SetCursorPos((x,y,))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
time.sleep(.1)
stop()
mouseClick()
def stop():
exit = win32api.mouse_event(win32con.MOUSEEVENTF_MOVE,1,1)
if exit:
menu()
menu()
我收到了以下调试消息:
Traceback (most recent call last):
File "" """File Location """ \Click Module.py", line 31, in <module>
menu()
File "" """File Location """ \Click Module.py", line 14, in menu
mouseClick()
File " """File Location """ \Click Module.py", line 17, in mouseClick
win32api.SetCursorPos((x,y,))
TypeError: an integer is required
请保存我的日期并给我饼干&lt; 3
答案 0 :(得分:0)
您的x
和y
被初始化为列表,并且未在功能中进行修改(您需要将它们global)。即使它们是str
,所以你需要做类似的事情:
x = int(input("Geef de X as op >> "))
y = int(input("Geef de Y as op >> "))
整个代码看起来像:
import win32api, win32con, win32gui
import random
import time
import os
menu = []
mouseClick = []
stop = []
x = None
y = None
def menu():
global x
global y
x = int(input("Geef de X as op >> "))
y = int(input("Geef de Y as op >> "))
mouseClick()
def mouseClick():
win32api.SetCursorPos((x,y,))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
time.sleep(.1)
stop()
mouseClick()
def stop():
exit = win32api.mouse_event(win32con.MOUSEEVENTF_MOVE,1,1)
if exit:
menu()
menu()
答案 1 :(得分:0)
感谢您的快速回复!
我的代码如下:
import win32api, win32con, win32gui
import random
import time
import os
menu = []
mouseClick = []
stop = []
def menu():
globals x,y
x = int(input("Geef de X as op >> "))
y = int(input("Geef de Y as op >> "))
mouseClick()
def mouseClick():
win32api.SetCursorPos((x,y,))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
time.sleep(5)
stop()
mouseClick()
def stop():
exit = win32api.mouse_event(win32con.MOUSEEVENTF_MOVE,1,1)
if exit:
menu()
menu()
我的调试代码说:
File "D:\Projecten\Runescape\RS_Bot_RuneMouse\Click Module.py", line 12
globals x,y
^
SyntaxError: invalid syntax
对全球的观察是什么?