Cette petite macro a pour but de simplifier certaines routines de travail répétitives (installations, configurations, bureautique, etc) dans le cas où la commande des contrôles (boutons...) par script est problématique et ne peut être effectuée que par clics (avec MouseClick)
Le script enregistre donc intuitivement (par "lecture" du pointeur de souris) une séquence de clics successifs à effectuer (position du pointeur, délai entre les clics), puis reproduit automatiquement cette séquence le nombre de fois désiré
3 modes possibles d'enregistrement des clics : par touche, par touche+clic, ou mode simulation
Ce code m'a été demandé initialement par mon geek de fiston pour un usage non précisé
Mais comme il est particulièrement adapté aux tâches bureautiques répétitives, je l'ai évidemment appelé "Bureautics Optimisation Tool"
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
Opt("GUIOnEventMode", 1)
Global $cibles, $start, $arrayPos[1][5], $nbclics, $n=0, $hit, $reg, $infotxt
Global $gui, $input_clics, $h = 40, $resized, $timer, $click, $begin
Global $ecran = 1, $radio_ecran, $radio_wnd, $wnd_handle, $wnd_title, $Paused
Global $key = "11", $keyname = "CTRL", $pausekey = "PAUSE"
HotKeySet("{"& $pausekey &"}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
$gui = GUICreate("B.O.T.", 165, $h+75, -1, 10)
GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate")
GUICtrlCreateGroup("", 5, 5, 155, 45)
GUICtrlSetResizing(-1, 802)
$radio_ecran = GUICtrlCreateRadio("pointeur en mode écran", 10, 12, 140, 15)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlSetResizing(-1, 802)
GUICtrlSetOnEvent (-1, "_mousemode")
$radio_wnd = GUICtrlCreateRadio("pointeur en mode fenêtre", 10, 30, 140, 15)
GUICtrlSetResizing(-1, 802)
GUICtrlSetOnEvent (-1, "_mousemode")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateLabel("cibles", 10, 13+75, 50, 17)
GUICtrlSetResizing(-1, 802)
GUICtrlCreateLabel("", 43, 8+75, 29, 24)
GUICtrlSetBkColor(-1, 0x00bb00) ;$GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetResizing(-1, 802)
$input_cibles = GUICtrlCreateInput($cibles, 45, 10+75, 25, 20, 2048+1) ;$ES_READONLY
GUICtrlSetBkColor(-1, 0xffffff)
GUICtrlSetResizing(-1, 802)
$btn_valid = GUICtrlCreateButton("Start", 80, 9+75, 50, 22)
GUICtrlSetResizing(-1, 802)
GUICtrlSetOnEvent (-1, "_start")
$btn_help = GUICtrlCreateButton("?", 140, 10+75, 20, 20)
GUICtrlSetResizing(-1, 802)
GUICtrlSetOnEvent (-1, "_help")
$btn_clic = GUICtrlCreateButton("Clic OFF", 5, 7+50, 60, 20)
GUICtrlSetResizing(-1, 802)
GUICtrlSetOnEvent (-1, "_setClic")
$btn_timer = GUICtrlCreateButton("Simulation OFF", 70, 7+50, 90, 20)
GUICtrlSetResizing(-1, 802)
GUICtrlSetOnEvent (-1, "_setTimer")
GUISetState()
Do
Sleep(10)
Until $start = 1
While 1
$reg = 0
If _IsPressed($key) Then
If $hit = $cibles Then
_resize()
EndIf
If $click Then
_mode_clic()
Else
Do
_enregistre()
Until not _IsPressed($key)
EndIf
EndIf
Wend
;=====================================================
Func _mousemode()
Switch @GUI_CtrlId
Case $radio_ecran
$ecran = 1
Opt("MouseCoordMode", 1)
Case $radio_wnd
_ChouzeWnd()
EndSwitch
EndFunc
Func _ChouzeWnd()
Opt("GUIOnEventMode", 0)
$chouzGui = GUICreate("Fenêtre cible", 280, 75, -1, 20)
GUICtrlCreateGroup("Choix de la fenêtre cible", 5, 5, 270, 65)
GUICtrlCreateLabel("Titre :", 10, 24, 45, 16)
$cible_title = GUICtrlCreateLabel("", 55, 23, 210, 16, $SS_CENTER+$SS_SUNKEN)
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlCreateLabel("Handle :", 10, 46, 50, 16)
$cible_handle = GUICtrlCreateLabel("", 55, 45, 75, 16, $SS_CENTER+$SS_SUNKEN)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$cible_btn = GUICtrlCreateButton("Choisir la fenêtre ...", 140, 44, 125, 18)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState()
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Opt("GUIOnEventMode", 1)
GuiDelete($chouzGui)
Return
Case $cible_btn
GuiCtrlSetData($cible_btn, "Cliquer sur la fenêtre")
While 1
If _IsPressed("01") Then
If WinActive("[active]")=$chouzGui or WinActive("[active]")=$gui Then
Opt("GUIOnEventMode", 1)
GuiDelete($chouzGui)
Return
Else
If $ecran = 1 Then
$wnd_handle = WinGetHandle("[active]")
$wnd_title = WinGetTitle($wnd_handle)
GuiCtrlSetData($cible_title, $wnd_title)
GuiCtrlSetData($cible_handle, $wnd_handle)
GuiCtrlSetData($cible_btn, "OK verrouillé")
GUICtrlSetState($cible_btn, $GUI_DISABLE)
GUICtrlSetState($radio_ecran, $GUI_DISABLE)
GUICtrlSetState($radio_wnd, $GUI_DISABLE)
$ecran = 0
Opt("MouseCoordMode", 2)
EndIf
EndIf
EndIf
Wend
EndSwitch
Wend
EndFunc
Func _mode_clic()
If _IsPressed("01") Then
Do
_enregistre()
Until not _IsPressed($key) and not _IsPressed("01")
EndIf
EndFunc
Func _enregistre()
If not $ecran Then WinActivate($wnd_handle)
If $reg = 0 Then
If $timer Then
If $begin<>0 Then
$time = Round(TimerDiff($begin)/1000)
GuiCtrlSetData($arrayPos[$hit-1][3], $time)
EndIf
$begin = TimerInit()
EndIf
$pos = MouseGetPos()
$arrayPos[$hit][0] = $pos[0]
$arrayPos[$hit][1] = $pos[1]
GUICtrlSetState($arrayPos[$hit][4], $GUI_SHOW)
GUICtrlSetBkColor($arrayPos[$hit][4], 0x00dd00)
$hit += 1
$reg = 1
EndIf
EndFunc
Func _start()
$start = not $start
If $start Then
GuiCtrlSetData($btn_valid, "Stop")
Else
If $cibles>0 Then
GuiCtrlDelete($btn_valid)
GUICtrlCreateLabel("nombre d'exécutions", 10, $h+($cibles*25)+82, 100, 17)
$input_clics = GUICtrlCreateInput("5", 115, $h+($cibles*25)+80, 30, 18, 1)
$btn_lancer = GUICtrlCreateButton("Lancer", 45, $h+($cibles*25)+105, 70, 25)
GUICtrlSetOnEvent (-1, "_lancer")
EndIf
If $timer Then
If $begin<>0 Then
$time = Round(TimerDiff($begin)/1000)
GuiCtrlSetData($arrayPos[$cibles-1][3], $time)
EndIf
EndIf
EndIf
EndFunc
Func _resize()
If $start = 1 Then
$cibles += 1
GuiCtrlSetData($input_cibles, $cibles)
ReDim $arrayPos[$cibles][5]
WinMove($gui, "", Default, Default, 170, $h+($cibles*25)+170)
GUICtrlCreateLabel("cible " & $cibles, 5, $h+($cibles*25)+53, 40, 17)
GUICtrlSetResizing(-1, 802)
$arrayPos[$cibles-1][3] = GUICtrlCreateInput("1", 45, $h+($cibles*25)+50, 30, 18, 1)
GUICtrlSetResizing(-1, 802)
GUICtrlCreateLabel("secondes", 80, $h+($cibles*25)+53, 50, 17)
GUICtrlSetResizing(-1, 802)
$arrayPos[$cibles-1][4] = GUICtrlCreateLabel("OK", 138, $h+($cibles*25)+51, 18, 15, 0x0201)
GUICtrlSetResizing(-1, 802)
GUICtrlSetState(-1, $GUI_HIDE)
EndIf
EndFunc
Func _lancer()
For $i = 0 to $cibles-1
$arrayPos[$i][2] = GuiCtrlRead($arrayPos[$i][3])
If Number($arrayPos[$i][2])=0 or $arrayPos[$i][2]<0.1 Then
MsgBox(48, "Erreur", "Faut un nombre supérieur à 0.1")
Return
EndIf
Next
$nbclics = GuiCtrlRead($input_clics)
If Number($nbclics)=0 or $nbclics<1 Then
MsgBox(48, "Erreur", "Faut un nombre supérieur à 0")
Return
EndIf
GuiDelete($gui)
Sleep(1000)
While 1
For $j = 0 to $cibles-1
If not $ecran Then WinActivate($wnd_handle)
MouseClick("primary", $arrayPos[$j][0], $arrayPos[$j][1], 1, 0)
Sleep($arrayPos[$j][2]*1000)
Next
$n += 1
If $n = $nbclics Then Terminate()
Wend
EndFunc
Func TogglePause()
$Paused = NOT $Paused
While $Paused
sleep(10)
ToolTip("En pause", Default, Default, "B.O.T.", 1, 1)
WEnd
ToolTip("")
EndFunc
Func _setTimer()
$timer = not $timer
$click = not $click
If $timer Then
GuiCtrlSetData($btn_timer, "Simulation ON")
GuiCtrlSetData($btn_clic, "Clic ON")
GUICtrlSetState($btn_clic, $GUI_DISABLE)
Else
GuiCtrlSetData($btn_timer, "Simulation OFF")
GuiCtrlSetData($btn_clic, "Clic OFF")
GUICtrlSetState($btn_clic, $GUI_ENABLE)
EndIf
EndFunc
Func _setClic()
$click = not $click
If $click Then
GuiCtrlSetData($btn_clic, "Clic ON")
Else
GuiCtrlSetData($btn_clic, "Clic OFF")
EndIf
EndFunc
Func Terminate()
Msgbox(0, "", " total " & $n & " exécutions" &@crlf&@crlf& " Bye", 8)
Exit
EndFunc
Func _IsPressed($sHexKey, $vDLL = 'user32.dll')
Local $a_R = DllCall($vDLL, "short", "GetAsyncKeyState", "int", '0x' & $sHexKey)
If @error Then Return SetError(@error, @extended, False)
Return BitAND($a_R[0], 0x8000) <> 0
EndFunc ;==>_IsPressed
Func _help()
Opt("GUIOnEventMode", 0)
$infogui = GUICreate("", 390, 402,-1,100, $WS_BORDER + $WS_POPUP, $WS_EX_TOPMOST + $WS_EX_DLGMODALFRAME )
GUICtrlCreateGroup("", 2, 0, 385, 400)
$infotxt = GUICtrlCreateLabel("", 20, 18, 360, 375)
Local $text = "- Mode écran" &@crlf & _
"Les coordonnées du pointeur sont absolues (écran)" &@crlf&@crlf & _
"- Mode fenêtre" &@crlf & _
"Les coordonnées du pointeur sont relatives (fenêtre)" &@crlf & _
"Dans ce mode la fenêtre-cible peut être déplacée pendant que le B.O.T. est actif (utiliser la pause)" &@crlf&@crlf & _
"Bouton Start pour l'activation - Touche active : " & $keyname &@crlf&@crlf & _
"- Mode simple (Clic OFF - Simulation OFF)" &@crlf & _
"Chaque appui sur la touche rajoute une cible et enregistre les coordonnées du pointeur de souris" &@crlf & _
"Bouton Stop pour la finalisation" &@crlf&@crlf & _
"- Mode clic (Clic ON - Simulation OFF)" &@crlf & _
"1er appui sur la touche : rajoute une cible" &@crlf & _
"2ème appui sur la touche + clic : enregistre les coordonnées" &@crlf & _
"OU" &@crlf & _
"appui sur la touche + clic : rajoute une cible et enregistre les coordonnées" &@crlf & _
"Bouton Stop pour la finalisation" &@crlf&@crlf & _
"- Mode Simulation (Simulation ON)" &@crlf & _
"Identique au mode clic, plus enregistrement du délai entre les clics" &@crlf & _
"Bouton Stop pour l'enregistrement du dernier délai et la finalisation" &@crlf&@crlf & _
"Touche " & $pausekey & " pour suspendre / reprendre l'activité" &@crlf & _
"Touche ESC pour quitter n'importe quand"
GUICtrlSetData($infotxt, $text)
GUISetState()
While GuiGetMsg()<>$infotxt
Wend
GUIDelete($infogui)
Opt("GUIOnEventMode", 1)
EndFunc