【问题标题】:Python click bot TypeError: an integer is required #CookieClickerV2Python click bot TypeError:需要一个整数#CookieClickerV2
【发布时间】:2016-05-29 22:47:56
【问题描述】:

帮助我卡住了。我想为“cookie clicker 2”制作一个自动点击器。你懂的。我喜欢饼干,我希望它们快点:P.....所以我写了这个脚本:

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

请保存我的一天并给我饼干

【问题讨论】:

    标签: python python-2.7 cookies


    【解决方案1】:

    您的xy 被初始化为列表,并且不会在函数中进行修改(您需要将它们设为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()
    

    【讨论】:

    • 更正了代码错误。 globals 现在应该可以工作了
    • 很高兴它成功了。希望这些不是永远持久的网络 cookie。他们让我消化不良。
    【解决方案2】:

    感谢您的快速回复!

    我的代码如下:

    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
    

    什么是全局观察?

    【讨论】:

      猜你喜欢
      • 2015-07-14
      • 2016-05-23
      • 1970-01-01
      • 1970-01-01
      • 2019-03-22
      • 2018-05-04
      • 1970-01-01
      • 2015-08-10
      • 2013-02-16
      相关资源
      最近更新 更多