I have attempted to modify the Autoclicker script on the pynput website, so that it saves the mouse button it is pressing to the file mousebutton.txt. However, the if statement doesn't seem to define 2 variables based on the single line in mousebutton.txt. (which should be a 1 or a 2)
# attempts to read from mousebutton.txt -- if it is not found, it creates it.
try:
with open('mouseButton.txt', 'r') as mbfile:
# read a list of lines into data if file found
mbdata = mbfile.readlines()
except FileNotFoundError as e:
if e.errno == errno.ENOENT:
# FileNotFoundError code here
with open('mouseButton.txt', 'a') as mbfile:
mbfile.write("0")
mbfile.close()
else:
raise
finally:
with open('mouseButton.txt', 'r') as mbfile:
# read a list of lines into data
mbdata = mbfile.readlines()
# saved mouse button
if mbdata == "0":
button = Button.left
currentButton = "left"
print("Current button: " + currentButton)
elif mbdata == "1":
button = button.right
currentButton = "right"
print("Current button: " + currentButton)
else:
button = Button.left
currentButton = "left"
print("Current button: " + currentButton)
Later in the code, where it closes mousebutton.txt
# closing mousebutton.txt
with open('mouseButton.txt', 'w') as file:
# file.writelines( data )
data_amount = 0
for x in range(read_lines):
file.write(mbdata[data_amount])
data_amount = data_amount + 1
file.write("\n")
file.close()
click_thread = ClickMouse(delay, button)
click_thread.start()
I keep getting an error here, saying:
line 160, in <module>
click_thread = ClickMouse(delay, button)
NameError: name 'button' is not defined
Aucun commentaire:
Enregistrer un commentaire