What do you think of my auto clicker script? Even though it's just for my own personal use, I'm thinking of using PyInstaller to turn it into an exe, so I know how to do that in the future.
import pyHook, threading
import tkinter as tk
from pyautogui import click
t1token = 0
threadsRun = 1
ac = 0
def simplegui():
def sunken():
"""keep startButton lowered and disabled.
hook keyboard, start clicks function"""
global threadsRun
startButton.config(relief=tk.SUNKEN, state=tk.DISABLED,
text="r=stop listening")
hm.HookKeyboard()
threadsRun = 1
t1 = threading.Thread(target=clicks, args=(startButton,),
name='clicks{}'.format(t1token))
t1.start()
def destroy():
"""exit program"""
global threadsRun, ac
ac = 0
threadsRun = 0
# Not sure if keyboard unhooks if press quit after press start
root.destroy()
startButton = tk.Button(root, text="Start", command=sunken,
height=10, width=20)
startButton.grid(row=1, column=0)
quitButton = tk.Button(root, text="Quit", command=destroy,
height=10, width=20)
quitButton.grid(row=1, column=1)
def clicks(startButton):
"""right clicks the mouse at 1k clicks per minute
also puts button back to normal state once done"""
global t1token
while threadsRun:
while ac:
click(clicks=17, interval=0.06, button='right')
t1token += 1
startButton.config(relief=tk.RAISED, state=tk.NORMAL, text="Start")
root = tk.Tk()
def OnKeyboardEvent(event):
"""A key was pressed"""
global threadsRun, ac
if event.Key == "R":
ac = 0
threadsRun = 0
hm.UnhookKeyboard()
return False
if event.Key == "T":
ac = not ac
return False
return True
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
simplegui()
root.mainloop()
pip installthem in command prompt \$\endgroup\$pip install pyhook3 pyautogui, as thepyhookpackage hasn't been updated since 2008. I can't vouch for any of these packages though. \$\endgroup\$