2

Help I got stuck. I want to make a auto clicker for "cookie clicker 2". You know. I love cookies and I want them fast :P..... soooo I wrote this script:

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()

I got the following Debug Message:

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

Please save my day and give me cookies <3

Mike KI
  • 23
  • 3

2 Answers2

0

Your x and y are initialized as lists and aren't modified within the functions(You need to make them global). Even if they were they would be str, so you will need to do something like:

x = int(input("Geef de X as op >> ")) 
y = int(input("Geef de Y as op >> ")) 

And the entire code would look something like:

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()
Community
  • 1
  • 1
Michal Frystacky
  • 1,418
  • 21
  • 38
0

Thank you for the fast responds!

My code is as followed:

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()

My debug code said:

  File "D:\Projecten\Runescape\RS_Bot_RuneMouse\Click Module.py", line 12
    globals x,y
            ^
SyntaxError: invalid syntax

What is the observation of global?

Mike KI
  • 23
  • 3