Skip to content

Instantly share code, notes, and snippets.

@vlad-bezden
Last active June 18, 2016 13:35
Show Gist options
  • Save vlad-bezden/1dd63b83e980e21a3a0e5317a6f4234a to your computer and use it in GitHub Desktop.
Save vlad-bezden/1dd63b83e980e21a3a0e5317a6f4234a to your computer and use it in GitHub Desktop.
Programs triggers mouse click every x number of seconds that can be passed via command line. If nothing passed via command line default click time will be 60 seconds. For more help use: python clicker.py -h
#
# Program triggers mouse click every 60 seconds
#
import pyautogui
import time
import threading
import argparse
runFlag = True
class ClickingThread(threading.Thread):
def __init__(self, clickingInterval):
threading.Thread.__init__(self)
self.clickingInterval = clickingInterval
self.daemon = True
def run(self):
global runFlag
while True:
if runFlag:
print(time.strftime('%H:%M:%S'))
pyautogui.click()
time.sleep(self.clickingInterval)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Simulate user mouse click')
parser.add_argument(
'-i',
'--interval',
type = int,
default = 60,
help = 'Interval time in seconds that mouse will click. Default time is 60 seconds')
args = parser.parse_args()
try:
runFlag = True
print('Mouse will click every {} seconds'.format(args.interval))
print('Press Enter for pause and resume program')
clickingThread = ClickingThread(args.interval)
clickingThread.start()
while True:
input()
runFlag = not runFlag
print('{}'.format('Running' if runFlag else 'Paused'))
except KeyboardInterrupt:
print('Exiting by user request')
except Exception as e:
print('Unexpected error:', str(e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment