Error in pyautogui, values

0

I want to create a macro that performs some tasks.

[OK] Step 1: 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] Step 2: 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

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 need to separate X and Y with : (colon). So far so good, the mistake comes in giving 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, I am sending only 2 (X, Y) The: is not being sent, it only serves to separate.

    
asked by anonymous 23.10.2017 / 17:33

1 answer

0

You can correct the problem by rewriting the sendMouse function so that when sending the values, do so using a list and values converted to 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")
    
27.10.2017 / 03:26