Skip to content

Instantly share code, notes, and snippets.

@subfission
Created February 24, 2022 06:51
Show Gist options
  • Save subfission/4af9f7a395c19161bd5c1582e017113d to your computer and use it in GitHub Desktop.
Save subfission/4af9f7a395c19161bd5c1582e017113d to your computer and use it in GitHub Desktop.
Click that mouse!
#!/usr/local/bin/python3
# Requires pynput package
from time import sleep
import sys
banner = """
by: subfission
======================================
╔╦╗┌─┐┬ ┬┌─┐┌─┐ ╔═╗┬ ┬┌─┐┬┌─┌─┐┬─┐
║║║│ ││ │└─┐├┤ ║ │ ││ ├┴┐├┤ ├┬┘
╩ ╩└─┘└─┘└─┘└─┘ ╚═╝┴─┘┴└─┘┴ ┴└─┘┴└─
======================================
Automate those mouse clicks!
usage: ./mouse_clicker.py [CLICKS]
"""
try:
from pynput.mouse import Button, Controller
except ModuleNotFoundError:
print("😵 Fatal Error! >>>")
print("You are missing the python3 module for pynput")
print(" run: pip3 install pynput\n")
exit(1)
def main():
try:
clicks = int(sys.argv[1])
if clicks < 1:
raise ValueError
except (IndexError, ValueError):
clicks = 100
mouse = Controller()
# Read pointer position
print('🖱️ Waiting 5 seconds for mouse to be positioned...')
sleep(5)
position = mouse.position
print('✅ Using current pointer position at {0}'.format(position))
print('Press ctrl+C to cancel within 5 seconds...', end="", flush=True)
for i in reversed(range(1, 6)):
print(i, end="", flush=True)
sleep(1)
print(".")
print("Planting a tree with every 10 clicks: %s:" % clicks)
print('----------------------------------')
print('')
for i in range(1, clicks):
mouse.position = position
mouse.click(Button.left, 2)
if i % 10 == 0:
print('🌱 ', end="", flush=True)
sleep(.1)
print("")
print("✅ Done")
if __name__ == '__main__':
print(banner)
try:
main()
except KeyboardInterrupt:
print("\n...Ending by request\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment