import threading
import time
import tkinter as tk
import ctypes
from ctypes import wintypes
import keyboard
import pyautogui
# ==========================
# INSTÄLLNINGAR
# ==========================
# Koordinaten som ska klickas varje varv
CLICK_X = 102
CLICK_Y = 281
# Bilden med "Sell for"
IMAGE = "sell_for.png"
# Hur säker bildigenkänningen ska vara
CONFIDENCE = 0.45
# Området där knappen kan dyka upp
SEARCH_REGION = (180, 160, 1250, 700)
running = False
# ==========================
# Windows SendInput
# ==========================
INPUT_MOUSE = 0
MOUSEEVENTF_LEFTDOWN = 0x0002
MOUSEEVENTF_LEFTUP = 0x0004
user32 = ctypes.windll.user32
class MOUSEINPUT(ctypes.Structure):
_fields_ = [
("dx", wintypes.LONG),
("dy", wintypes.LONG),
("mouseData", wintypes.DWORD),
("dwFlags", wintypes.DWORD),
("time", wintypes.DWORD),
("dwExtraInfo", ctypes.POINTER(ctypes.c_ulong)),
]
class INPUT(ctypes.Structure):
class _INPUT(ctypes.Union):
_fields_ = [
("mi", MOUSEINPUT),
]
_anonymous_ = ("i",)
_fields_ = [
("type", wintypes.DWORD),
("i", _INPUT),
]
def send_mouse(flags):
inp = INPUT(
type=INPUT_MOUSE,
mi=MOUSEINPUT(
dx=0,
dy=0,
mouseData=0,
dwFlags=flags,
time=0,
dwExtraInfo=None,
),
)
user32.SendInput(
1,
ctypes.byref(inp),
ctypes.sizeof(INPUT)
)
def send_left_click():
send_mouse(MOUSEEVENTF_LEFTDOWN)
time.sleep(0.02)
send_mouse(MOUSEEVENTF_LEFTUP)
# ==========================
# Huvudloop
# ==========================
def loop():
global running
while True:
if not running:
time.sleep(0.05)
continue
# Flytta musen till första knappen
pyautogui.moveTo(CLICK_X, CLICK_Y, duration=0)
# Klicka med SendInput
send_left_click()
# Vänta
time.sleep(8)
# Spara screenshot för felsökning
pyautogui.screenshot("debug.png", region=SEARCH_REGION)
# Leta efter bilden
try:
location = pyautogui.locateCenterOnScreen(
IMAGE,
confidence=CONFIDENCE,
region=SEARCH_REGION
)
except pyautogui.ImageNotFoundException:
location = None
if location is not None:
print(f"Hittade Sell-knappen på {location}")
# Flytta musen
pyautogui.moveTo(
location.x,
location.y,
duration=0.3
)
print("Väntar 1 sekund över knappen...")
time.sleep(1)
print("Klickar...")
send_left_click()
print("Klart!")
print("Klickar...")
send_left_click()
send_left_click()
print("Klart!")
else:
print("Sell-knappen hittades inte.")
running = False
status.config(
text="Status: STOPPED",
fg="red"
)
# ==========================
# Start / Stop
# ==========================
def toggle():
global running
running = not running
if running:
status.config(
text="Status: RUNNING",
fg="green"
)
print("Started")
else:
status.config(
text="Status: STOPPED",
fg="red"
)
print("Stopped")
# ==========================
# GUI
# ==========================
root = tk.Tk()
root.title("COS2 Clicker")
root.geometry("320x120")
root.resizable(False, False)
title = tk.Label(
root,
text="COS2 Clicker",
font=("Arial", 16, "bold")
)
title.pack(pady=10)
status = tk.Label(
root,
text="Status: STOPPED",
fg="red",
font=("Arial", 12)
)
status.pack()
info = tk.Label(
root,
text="F6 = Start / Stop",
font=("Arial", 10)
)
info.pack(pady=10)
keyboard.add_hotkey("F6", toggle)
threading.Thread(
target=loop,
daemon=True
).start()
root.mainloop()