Last active
February 26, 2024 14:28
-
-
Save TheRealRyGuy/5db07ee1c9b02980b7e4fb91ee26527d to your computer and use it in GitHub Desktop.
An autoclicker I made in class trying to relearn Python, but really to play Cookie Clicker. Lots of Stack Overflowing was done for the general concepts / remembering certain concepts of Python, and this could very well be significantly more optimized
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
import time | |
import threading | |
from pynput import mouse | |
from pynput.mouse import Button, Controller | |
class Clicker(threading.Thread): | |
def __init__(self, cps, window, desktop): | |
super(Clicker, self).__init__() | |
self.delay = (1/int(cps)) | |
self.window = window | |
self.live = False | |
self.desktop = desktop | |
self.mouse = Controller() | |
def start_clicking(self): | |
self.live = True | |
print("Starting clicking!") | |
def stop(self): | |
self.live = False | |
print("Stopped Clicking!") | |
self.stop.set() | |
def running(self): | |
w= self.desktop.from_point(self.mouse.position[0], self.mouse.position[1]) | |
return self.desktop.from_point(self.mouse.position[0], self.mouse.position[1]).process_id() == int(self.window) | |
def run(self): | |
while self.live: | |
while self.running(): | |
self.mouse.click(Button.left) |
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
from autoclicker import Clicker | |
from pywinauto import Desktop | |
def main(): | |
desktop = Desktop(backend="uia") | |
cps = input("How fast do you want to click (CPS): ") | |
while True: | |
try: | |
int(cps) | |
break | |
except ValueError: | |
print("Invalid integer!") | |
windows = desktop.windows() | |
for x in windows: | |
print(f"{x.process_id()} - {x.window_text()}") | |
while True: | |
window = input("What window do you want to choose? Put in the process id: ") | |
try: | |
int(window) | |
except ValueError: | |
print("Invalid integer!") | |
return | |
selected = next(filter(lambda x: x.process_id() == int(window), desktop.windows())) | |
if(selected == None): | |
print("You put in an invalid Window!") | |
return | |
print(f"Clicking on {window}!") | |
break | |
clicker = Clicker(cps, window, desktop) | |
clicker.start_clicking() | |
clicker.start() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment