pyautogui error, values

Asked

Viewed 66 times

0

I want to create a macro that performs some tasks.

[OK] 1° Step: Remember the X and Y. COD:

def recordMouse():
time.sleep(5)
print "New record in 3s"
x, y = pyautogui.position()    
c = open('Position.txt', 'a')
c.write(str(x) + ":" + str(y) + "\n")
c.close()
print "X ["+str(x)+"]  Y ["+str(y)+"] Position added!"
pyautogui.click(x,y)
mouse()

[OK] 2° Step: Read line by line and send to click COD:

def readLine():
arq = open("Position.txt", 'r')
texto = arq.readlines()
for linha in texto :
    sendMouse(str(linha))
    #print linha
arq.close()     

Step 3: Click on

def sendMouse(line):
if ":" in line:
    dados = line.split(":")
    x = dados[0]
    y = dados[1]
    print "Click on: X:"+str(x)+" Y:"+str(y)+""
    pyautogui.click(x,y)
else:
    print("Line error")

In this part, I must separate the X and Y, for :(two points). So far so good, the error comes at the time to give the CLICK.

pyautogui.click(x,y)

ERROR:Valueerror: The supplied Sequence must have Exactly 2 Elements (3 Were Received).

Informs that I am sending 3 values, and I am sending only 2(X,Y) O : is not being sent, it serves only to separate.

  • 1

    The purpose of the module PyAutoGui is only simulate operations with the mouse and keyboard and does not provide interface to the capture of clicks mouse. If the intent of the function recordMouse() is to capture mouse clicks, this is not possible with the PyAutoGui.

  • Use the module Pynput to record the mouse and keyboard.

1 answer

0

You can fix the problem by rewriting the sendMouse function, so that when sending the values, do so using a list and converted values into integers. That is, as follows::

def sendMouse(line):
  if ":" in line:
        dados = line.split(":")
        x = dados[0]
        y = dados[1]
        print("Click on: X:"+str(x)+" Y:"+str(y)+"")
        pyautogui.click([int(x),int(y)])
  else:
        print("Line error")
  • Note: I rewrote your code here, and now it seems to run correctly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.