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.
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 functionrecordMouse()
is to capture mouse clicks, this is not possible with thePyAutoGui
.– Lacobus
Use the module
Pynput
to record the mouse and keyboard.– Lacobus