1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
|
##### Importation des bibliothèques utilisé #####
import tkinter as tk
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from tkinter import LEFT, RIGHT, TOP, BOTTOM
from tkinter import filedialog, simpledialog
from tkinter import messagebox, Toplevel
from tkinter import PhotoImage
from pynput import mouse
import webbrowser
import pyautogui
import keyboard
import json
import re
import os, sys
# Test de fonctionnement de keyboard
try:
# Test simple : tenter d'enregistrer un raccourci clavier temporaire
id_test = keyboard.add_hotkey("ctrl+shift+alt+9", lambda: None)
keyboard.remove_hotkey(id_test)
except Exception as e:
messagebox.showerror(
"Erreur avec le module 'keyboard'\n",
"Le module 'keyboard' ne fonctionne pas correctement.\n"
"La touche de démarrage ne sera pas fonctionnelle.\n"
"Essayez d'exécuter ce programme en tant qu'administrateur.\n\n"
f"Détails : {e}"
)
##### Main #####
# Creation de la fenetre
Fenetre_Principale = ttk.Window(themename="vapor")
Fenetre_Principale.title("Auto-Clicker")
Fenetre_Principale.resizable(False, False)
# Variable global qui dit si le clique est en marche ou non
Actif = None
# Variable global qui prend en variable le clicque pour qu'il puisse etre cancel
Id_Touche_Ecoute = None
# Fonction choix de l'action via titre boutton
def startstop():
global Actif
try :
if Actif is None:
start_clicking()
elif Actif is not None:
stop_clicking()
except Exception as e:
messagebox.showerror("Erreur", str(e))
##### Paramète de premier lancement #####
# Création du json setting s'il n'existe pas
try :
if not os.path.exists("setting/"):
os.makedirs("setting/")
if not os.path.exists("setting/setting_start.json"):
parametres = {
"default_h": "0",
"default_min": "0",
"default_s": "1",
"default_ms": "0",
"choix_click": 1,
"choix_position": 1,
"Delai_premier_click": "2000",
"Valeur_X": "0",
"Valeur_Y": "0",
"Touche_demarrage" : "F6"
}
with open("setting/setting_start.json", "w") as fichier:
json.dump(parametres, fichier, indent=4)
except Exception as e:
messagebox.showerror("Erreur", str(e))
# Initialisation des variables
default_h = tk.StringVar(Fenetre_Principale, value="0")
default_min = tk.StringVar(Fenetre_Principale, value="0")
default_s = tk.StringVar(Fenetre_Principale, value="0")
default_ms = tk.StringVar(Fenetre_Principale, value="0")
choix_click = tk.IntVar(Fenetre_Principale, value=1)
choix_position = tk.IntVar(Fenetre_Principale, value=1)
Delai_premier_click = tk.StringVar(Fenetre_Principale, value="2000")
Valeur_X = tk.StringVar(Fenetre_Principale, value="0")
Valeur_Y = tk.StringVar(Fenetre_Principale, value="0")
Touche_demarrage = tk.StringVar(Fenetre_Principale, value="F6")
# Fonction qui change le text sur le bouton
def Update_Text_Button():
Bouton_Start.config(text=f"{Action} ({Touche_demarrage.get()})")
#Mettre a jour la touche de lancement
def Update_touche():
global Id_Touche_Ecoute
if Id_Touche_Ecoute:
keyboard.remove_hotkey(Id_Touche_Ecoute)
Id_Touche_Ecoute = keyboard.add_hotkey(Touche_demarrage.get(), startstop)
# Charger un fichier de setting
def charger_setting(fichier_choisi):
# Apelle de toute les variable global pour les inclurent dans la fonction
global default_h, default_min, default_s, default_ms, choix_click, choix_position, Valeur_X, Valeur_Y
try:
with open(fichier_choisi, "r") as fichier:
parametres = json.load(fichier)
# Mise a jour de toute les variable globales
default_h.set(parametres.get("default_h"))
default_min.set(parametres.get("default_min"))
default_s.set(parametres.get("default_s"))
default_ms.set(parametres.get("default_ms"))
choix_click.set(parametres.get("choix_click"))
choix_position.set(parametres.get("choix_position"))
Delai_premier_click.set(parametres.get("Delai_premier_click"))
Valeur_X.set(parametres.get("Valeur_X"))
Valeur_Y.set(parametres.get("Valeur_Y"))
Touche_demarrage.set(parametres.get("Touche_demarrage"))
Update_touche()
except Exception as e:
messagebox.showerror("Erreur", str(e))
charger_setting("setting/setting_start.json")
Update_touche()
##### Fonction pour le click #####
# Fonction qui clique avec un temps de repos
def auto_click(Interval):
global Actif
global choix_click
try :
if int(choix_click.get()) == 1:
pyautogui.click(button="left")
Actif = Fenetre_Principale.after(Interval, lambda: auto_click(Interval))
elif int(choix_click.get()) == 2:
pyautogui.click(button="right")
Actif = Fenetre_Principale.after(Interval, lambda: auto_click(Interval))
except Exception as e:
messagebox.showerror("Erreur", str(e))
# Fonction qui clique avec un temps de repos avec positionnement du curseur
def auto_click_positionnement(Interval, x, y):
global Actif
try :
pyautogui.moveTo(x, y)
if int(choix_click.get()) == 1:
pyautogui.click(button="left")
Actif = Fenetre_Principale.after(Interval, lambda: auto_click_positionnement(Interval, x, y))
elif int(choix_click.get()) == 2:
pyautogui.click(button="right")
Actif = Fenetre_Principale.after(Interval, lambda: auto_click_positionnement(Interval, x, y))
except Exception as e:
messagebox.showerror("Erreur", str(e))
# Fonction pour démarrer l'auto-clicker
def start_clicking():
global Actif
Bouton_Start['text'] = f"Arrêter ({Touche_demarrage.get()})"
try:
h = int(Interval_h.get()) if Interval_h.get().isdigit() else 0
m = int(Interval_min.get()) if Interval_min.get().isdigit() else 0
s = int(Interval_s.get()) if Interval_s.get().isdigit() else 0
ms = int(Interval_ms.get()) if Interval_ms.get().isdigit() else 0
Interval = h * 3600000 + m * 60000 + s * 1000 + ms
if Interval == 0:
Interval = 1000
except Exception as e:
messagebox.showerror("Erreur", str(e))
if choix_position.get() == 1:
Actif = Fenetre_Principale.after(2000, lambda: auto_click(Interval))
elif choix_position.get() == 2:
x = int(Valeur_X.get())
y = int(Valeur_Y.get())
Actif = Fenetre_Principale.after(2000, lambda: auto_click_positionnement(Interval, x, y))
# Fonction pour arrêter l'auto-clicker
def stop_clicking():
global Actif
Fenetre_Principale.after_cancel(Actif)
Actif = None
Bouton_Start['text'] = f"Démarrer ({Touche_demarrage.get()})"
##### Fonction barre de menu #####
def Sauvegarder():
try:
parametres = {
"default_h": default_h.get(),
"default_min": default_min.get(),
"default_s": default_s.get(),
"default_ms": default_ms.get(),
"choix_click": choix_click.get(),
"choix_position": choix_position.get(),
"Delai_premier_click": Delai_premier_click.get(),
"Valeur_X": Valeur_X.get(),
"Valeur_Y": Valeur_Y.get(),
"Touche_demarrage" : Touche_demarrage.get()
}
with open("setting/setting_start.json", "w") as fichier:
json.dump(parametres, fichier, indent=4)
except Exception as e:
messagebox.showerror("Erreur", str(e))
def Reset_setting():
default_h.set("0")
default_min.set("0")
default_s.set("1")
default_ms.set("0")
choix_click.set(1)
choix_position.set(1)
Delai_premier_click.set("2000")
Valeur_X.set("0")
Valeur_Y.set("0")
Touche_demarrage.set("F6")
def importer_setting():
fichier_choisi = filedialog.askopenfilename(
title="Choisir un fichier JSON",
filetypes=[("Fichiers JSON", "*.json")],
initialdir="setting" # Dossier par défaut
)
if re.search(r"^.*\.json$", fichier_choisi):
charger_setting(fichier_choisi)
else:
tk.messagebox.showinfo("Erreur", "Mauvais fichier")
def exporter_setting():
nom_fichier = simpledialog.askstring("Exporter les parametres actuelle", "Nom du fichier :")
if not nom_fichier:
return
if not re.search(r"^.*\.json$", nom_fichier):
nom_fichier += ".json"
if os.path.exists(f"setting/{nom_fichier}"):
Reponse_Remplacer = tk.messagebox.askyesno(f"Fichier existant", f"Le fichier {nom_fichier} existe déja voulez vous le remplacer ? ")
if not Reponse_Remplacer:
return
try:
parametres = {
"default_h": default_h.get(),
"default_min": default_min.get(),
"default_s": default_s.get(),
"default_ms": default_ms.get(),
"choix_click": choix_click.get(),
"choix_position": choix_position.get(),
"Delai_premier_click": Delai_premier_click.get(),
"Valeur_X": Valeur_X.get(),
"Valeur_Y": Valeur_Y.get(),
"Touche_demarrage" : Touche_demarrage.get()
}
with open(f"setting/{nom_fichier}", "w") as fichier:
json.dump(parametres, fichier, indent=4)
except Exception as e:
messagebox.showerror("Erreur", str(e))
def A_propos():
A_propos_window = tk.Toplevel()
A_propos_window.title("A propos")
A_propos_window.resizable(False, False)
msg_apropos = ("Nom du programme : AutoClicker\n"
"Version : 1.0\n"
"Développé par : Devoghlockst\n\n"
"Ce programme est un auto-clicker\n\n"
"Parametrage possible :\n"
"- Temps entre les cliques\n"
"- Type de clique\n"
"- Position du clique\n"
"- Délai de lancement du premier clique \n"
"- Touche de démarrage\n\n"
"Les paramètres peuvent être enregistrés, exportés et importés au format JSON."
)
label_texte = tk.Label(A_propos_window, text=msg_apropos, justify="left")
label_texte.pack(padx=10, pady=10)
def Aide():
Aide_window = tk.Toplevel()
Aide_window.title("Aide")
Aide_window.resizable(False, False)
msg_aide = ("La sauvegarde du paramétrage est stockée par défaut dans le dossier créer par l'autoclicker nomer setting.\n\n"
"Tous les fichiers paramètre sauvegardé sont aux format json.\n\n"
"Il y a un délai de 2seconde avant le début du premier clique.")
label_texte = tk.Label(Aide_window, text=msg_aide, justify="left")
label_texte.pack(padx=10, pady=10)
def Touche_set():
global Touche_demarrage
def Key_Press(event):
global Touche_demarrage
Touche_demarrage.set(event.keysym) #Recupération de la touche presser
Update_touche()
popup.destroy()
Update_Text_Button()
popup = tk.Toplevel()
popup.title("Changement de la touche de lancement")
popup.resizable(False, False)
label = tk.Label(popup, text="Appuyer sur une touche de votre clavier pour paramètrer la touche de démarrage.")
label.pack(expand=True, fill="both", padx=5, pady=5)
#Paralysie de l'utilisateur
popup.grab_set()
popup.focus_force()
#Quand une touche est appuyer faire la fonction on_key_press
popup.bind("<KeyPress>", Key_Press)
def Recuperation_Position_Click():
def on_click(x, y, button, pressed):
Valeur_X.set(x)
Valeur_Y.set(y)
Listener.stop()
Fenetre_Principale.deiconify()
Fenetre_Principale.after(50, lambda: Fenetre_Principale.lift())
Fenetre_Principale.withdraw()
#Ajout d'un écouteur de clique
Listener = mouse.Listener(on_click=on_click)
Listener.start()
def resource_path(relative_path):
try:
base_path = sys._MEIPASS # Acces via MEIPASS
except AttributeError:
base_path = os.path.abspath(".") # Acces via dossier actuel
return os.path.join(base_path, relative_path)
# ### en cours ###
# ###### A FAIRE ######
# Changer la langue en anglais ou fr via le menu parametre (plus tard)
# Ajouter la possibiliter de combinaison de touche pour le changement de touche (plus tard)
# Ajouter une variable de temps pour le temps que met l'autoclicker a démarer
# ###### A FAIRE ######
#############################################################################
##### Interface tkinter #####
# Icone du la fenetre
Fenetre_Principale.iconbitmap(resource_path("Image_icon/Icone_Mouse.ico"))
# Création de la barre de menu principale (Tkinter classique)
Menu_Principale = tk.Menu(Fenetre_Principale)
# Icone de la barre menu
Icone_Save = PhotoImage(file=resource_path("Image_icon/Save.png"))
Icone_Exit = PhotoImage(file=resource_path("Image_icon/Exit.png"))
Icone_Import = PhotoImage(file=resource_path("Image_icon/Import.png"))
Icone_Export = PhotoImage(file=resource_path("Image_icon/Export.png"))
Icone_Keyboard = PhotoImage(file=resource_path("Image_icon/Keyboard.png"))
Icone_Reset = PhotoImage(file=resource_path("Image_icon/Reset.png"))
Icone_Help = PhotoImage(file=resource_path("Image_icon/Help.png"))
Icone_Propos = PhotoImage(file=resource_path("Image_icon/Propos.png"))
# Menu "Fichier" : options pour sauvegarder ou quitter
Menu_fichier = tk.Menu(Menu_Principale, tearoff=0)
Menu_fichier.add_command(label="Sauvegarder les paramètres", image=Icone_Save, compound="left", command=Sauvegarder)
Menu_fichier.add_command(label="Quitter", image=Icone_Exit, compound="left", command=Fenetre_Principale.quit)
Menu_Principale.add_cascade(label="Fichier", menu=Menu_fichier)
# Menu "Paramètres" : import/export des réglages, personnalisation des touches, réinitialisation
Menu_setting = tk.Menu(Menu_Principale, tearoff=0)
Menu_setting.add_command(label="Importer les paramètres", image=Icone_Import, compound="left", command=importer_setting)
Menu_setting.add_command(label="Exporter les paramètres", image=Icone_Export, compound="left", command=exporter_setting)
Menu_setting.add_command(label="Changer la touche de démarrage", image=Icone_Keyboard, compound="left", command=Touche_set)
Menu_setting.add_command(label="Réinitialiser les paramètres", image=Icone_Reset, compound="left", command=Reset_setting)
Menu_Principale.add_cascade(label="Paramètres", menu=Menu_setting)
# Menu "Plus" : accès à l'aide et aux informations sur l'application
Menu_plus = tk.Menu(Menu_Principale, tearoff=0)
Menu_plus.add_command(label="Aide", image=Icone_Help, compound="left", command=Aide)
Menu_plus.add_command(label="À propos", image=Icone_Propos, compound="left", command=A_propos)
Menu_Principale.add_cascade(label="Plus", menu=Menu_plus)
# Application de la barre de menu à la fenêtre principale
Fenetre_Principale.config(menu=Menu_Principale)
# Conteneur principal de l'interface
Frame_Principale = ttk.Frame(Fenetre_Principale, padding=15)
Frame_Principale.pack(fill=BOTH, expand=True)
# Section : Réglage de l'Intervalle entre les clics
Frame_Interval = ttk.LabelFrame(Frame_Principale, text="Intervalle entre les clics", padding=(15,10))
Frame_Interval.grid(row=0, column=0, columnspan=2, sticky="ew", pady=(0,15))
Frame_Interval.columnconfigure((0,2,4,6), weight=1) # Colonnes des Spinbox (extensibles)
Frame_Interval.columnconfigure((1,3,5,7), weight=0) # Colonnes des labels (fixes)
# Spinbox pour heures / minutes / secondes / millisecondes avec leurs labels
Interval_h = tk.Spinbox(Frame_Interval, from_=0, to=999999, width=5, textvariable=default_h, font=("Consolas", 11), justify="center")
Interval_h.grid(row=0, column=0, padx=(3,8), pady=5, sticky="ew")
ttk.Label(Frame_Interval, text="h").grid(row=0, column=1, sticky=W, padx=(0,15))
Interval_min = tk.Spinbox(Frame_Interval, from_=0, to=999999, width=5, textvariable=default_min, font=("Consolas", 11), justify="center")
Interval_min.grid(row=0, column=2, padx=(3,8), pady=5, sticky="ew")
ttk.Label(Frame_Interval, text="min").grid(row=0, column=3, sticky=W, padx=(0,15))
Interval_s = tk.Spinbox(Frame_Interval, from_=0, to=999999, width=5, textvariable=default_s, font=("Consolas", 11), justify="center")
Interval_s.grid(row=0, column=4, padx=(3,8), pady=5, sticky="ew")
ttk.Label(Frame_Interval, text="s").grid(row=0, column=5, sticky=W, padx=(0,15))
Interval_ms = tk.Spinbox(Frame_Interval, from_=0, to=999999, width=5, textvariable=default_ms, font=("Consolas", 11), justify="center")
Interval_ms.grid(row=0, column=6, padx=(3,8), pady=5, sticky="ew")
ttk.Label(Frame_Interval, text="ms").grid(row=0, column=7, sticky=W, padx=(0,5))
# Section : Définir la position du curseur
Frame_Position_Curseur = ttk.LabelFrame(Frame_Principale, text="Position du curseur", padding=(15,10))
Frame_Position_Curseur.grid(row=1, column=0, sticky="nsew", padx=(0,10))
Frame_Position_Curseur.columnconfigure(0, weight=1)
# Choix entre utiliser la position actuelle ou en définir une manuellement
Position_Actuelle = ttk.Radiobutton(Frame_Position_Curseur, text="Position actuelle", variable=choix_position, value=1)
Position_Actuelle.grid(row=0, column=0, sticky="ew", pady=5)
Position_Defini = ttk.Radiobutton(Frame_Position_Curseur, text="Définir une position", variable=choix_position, value=2)
Position_Defini.grid(row=1, column=0, sticky="ew", pady=5)
# Sous-section pour définir manuellement les coordonnées X et Y
Frame_Position_Valeur = ttk.LabelFrame(Frame_Position_Curseur, text="Valeurs X et Y", padding=(10,10))
Frame_Position_Valeur.grid(row=2, column=0, sticky="ew", pady=(10,0))
Frame_Position_Valeur.columnconfigure((1,3), weight=1)
# Bouton pour sélectionner automatiquement une position à lécran
Bouton_Position = ttk.Button(Frame_Position_Valeur, text="Sélectionner une position", command=Recuperation_Position_Click, bootstyle="warning-outline")
Bouton_Position.grid(row=0, column=0, columnspan=4, sticky="ew", pady=(0,10))
# Champs de saisie des coordonnées X et Y
ttk.Label(Frame_Position_Valeur, text="X :").grid(row=1, column=0, sticky=E, padx=5)
Position_Valeur_X = ttk.Entry(Frame_Position_Valeur, textvariable=Valeur_X, width=8)
Position_Valeur_X.grid(row=1, column=1, sticky="ew", padx=5)
ttk.Label(Frame_Position_Valeur, text="Y :").grid(row=1, column=2, sticky=E, padx=5)
Position_Valeur_Y = ttk.Entry(Frame_Position_Valeur, textvariable=Valeur_Y, width=8)
Position_Valeur_Y.grid(row=1, column=3, sticky="ew", padx=5)
# Section : Choix du type de clic, délai au lancement, bouton démarrer
Frame_Choix_Click_Button = ttk.Frame(Frame_Principale)
Frame_Choix_Click_Button.grid(row=1, column=1, sticky="nsew")
Frame_Choix_Click_Button.columnconfigure(0, weight=1)
# Sous-section : choix entre clic gauche ou droit
Frame_choix_click = ttk.LabelFrame(Frame_Choix_Click_Button, text="Choix du clic", padding=(10,10))
Frame_choix_click.grid(row=0, column=0, sticky="ew")
Click_Gauche = ttk.Radiobutton(Frame_choix_click, text="Gauche", variable=choix_click, value=1)
Click_Gauche.pack(side=LEFT, expand=True, fill="x", padx=10, pady=5)
Click_Droite = ttk.Radiobutton(Frame_choix_click, text="Droite", variable=choix_click, value=2)
Click_Droite.pack(side=LEFT, expand=True, fill="x", padx=10, pady=5)
# Sous-section : Délai au lancement
Frame_delai_debut = ttk.LabelFrame(Frame_Choix_Click_Button, text="Délai au démarrage", padding=(10,10))
Frame_delai_debut.grid(row=1, column=0, sticky="ew")
Delai_debut = tk.Spinbox(Frame_delai_debut, from_=0, to=9999999999, width=10, textvariable=Delai_premier_click, font=("Consolas", 11), justify="center")
Delai_debut.grid(row=0, column=0, sticky="ew", padx=10, pady=5)
ttk.Label(Frame_delai_debut, text="ms").grid(row=0, column=1, sticky="w", padx=(0, 15))
# Bouton principal pour démarrer/arrêter l'action automatisée
Bouton_Start = ttk.Button(Frame_Choix_Click_Button, text=f"Démarrer ({Touche_demarrage.get()})", command=startstop, bootstyle="warning-outline")
Bouton_Start.grid(row=2, column=0, sticky="ew", pady=(15, 0), ipady=15) # Hauteur accrue avec `ipady`
# Rendre la grille principale flexible et adaptative
Frame_Principale.rowconfigure(1, weight=1)
Frame_Principale.columnconfigure(0, weight=1)
Frame_Principale.columnconfigure(1, weight=1)
# Lancement de la boucle principale Tkinter
if __name__ == "__main__":
Fenetre_Principale.mainloop() |