Last active
June 18, 2016 13:35
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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