0
votes

I tried to make It clicks to random coordinates but it gave this error

Exception has occurred: TypeError integer argument expected, got float

code:

import time
import random
import keyboard
import win32api, win32con

firstkey = input ('def first key =')
cordinate = random.uniform(391, 904)
cordinatetwo = random.uniform(158, 671)
h = 0

def click(x,y):
    win32api.SetCursorPos((x,y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
    time.sleep(0.01)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)

keyboard.wait(firstkey)
if keyboard.is_pressed(firstkey):
    while h < 25:
        click(cordinate,cordinatetwo)
        h += 1

I am using VSC (and I think my English is bad)

2
While I may not know much about win32api, I can tell that random.uniform() returns a floating point number, and is causing your issue. - sybrg

2 Answers

0
votes

I think you need to change

random.uniform(391, 904) to random.randit(391, 904) and cordinatetwo = random.uniform(158, 671) to random.randint as well.

The uniform() method returns a random floating number between the two specified numbers (both included).

-1
votes

I believe your error is because of random.uniform() try changing it to randint()

import time
import random
import keyboard
import win32api, win32con
from random import randint

firstkey = input ('def first key =')
cordinate = randint(391, 904)
cordinatetwo = randint(158, 671)
h = 0

def click(x,y):
    win32api.SetCursorPos((x,y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
    time.sleep(0.01)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)

keyboard.wait(firstkey)
if keyboard.is_pressed(firstkey):
    while h < 25:
        click(cordinate,cordinatetwo)
        h += 1