Skip to navigation
Example of an autohotkey v2 Script
24.04.25
Example of autohotkey v2 script * Logging to text logfile with size rotator * waiting for Control Elements to come up * Comparing variables * Set message to the statusbar to the windows app * Loop * Kill App ```ahk ; https://www.autohotkey.com/docs/v2/lib/Sleep.htm Number := 0 Style := "" LastStyle := "" Logfile := "balance.log" if FileExist(Logfile) { Size := FileGetSize("balance.log", "K") if Size > 6000 FileDelete "balance.log" } FileAppend "...start tamuz" . "`n", "balance.log" Run "C:\0_scripts\tamuz\applic\uniRTE.exe /ini=C:\0_scripts\Tamuz\Tamuz\user.ini @C:\0_scripts\Tamuz\env\231.ini /[MAGIC_LOGICAL_NAMES]WorkingDir =C:\0_scripts\Tamuz\Tamuz" WinWaitActive("Salamander", , 60) WaitControlExist("MAGIC_GDT1") FileAppend "...tamuz open" . "`n", "balance.log" ControlFocus "MAGIC_GDT1","Salamander Factory" Send "Ofer" Send "{TAB}" Send "1234" Sleep 100 ControlFocus "Button2","Salamander Factory","Confirm" ControlClick "Button2","Salamander Factory","Confirm" Sleep 100 FileAppend "...tamuz loggin" . "`n", "balance.log" WaitControlExist("Button12") FileAppend "...click button Raw Material Stock" . "`n", "balance.log" ControlFocus "Button12","Salamander Factory","Raw Material Stock" ControlClick "Button12","Salamander Factory","Raw Material Stock" WaitControlExist("Button2") FileAppend "...tab to enter 9" . "`n", "balance.log" Send "{Down 4}" sleep 100 Send "9" sleep 100 Send "{Down}" sleep 100 Send "24" sleep 100 FileAppend "...try to click Button Perform" . "`n", "balance.log" WaitControlExist("Button2") ControlFocus "Button2","Salamander Factory","Perform" ControlClick "Button2","Salamander Factory","Perform" FileAppend "...enter list for loop" . "`n", "balance.log" ControlSetText("Autorobot", "msctls_statusbar321") ;Send "{Down 35}" FileAppend "...start loop" . "`n", "balance.log" loop { WaitControlExist("MAGIC_GDT1") ControlFocus "MAGIC_GDT1","Salamander Factory" ;WaitControlExist("MAGIC_GDT1") ;ControlFocus "MAGIC_GDT1","Salamander Factory" Style := ControlGetText("MAGIC_GDT1","Salamander Factory") ;sleep 100 Msg := Number . "x | " . LastStyle . " | " . Style . " | Ok" ControlSetText(Msg, "msctls_statusbar321") FileAppend Msg . "`n", "balance.log" if (Style ~= "9999|20") { FileAppend "...skip style: " . Style "`n", "balance.log" LastStyle := Style Send "{Down}" Continue } if(Style = "\/ \/") { FileAppend "...skip style: " . Style "`n", "balance.log" LastStyle := Style Continue } if(Style = "") { FileAppend "...error style is empty" . "`n", "balance.log" LastStyle := Style Send "{Down}" Continue } if(Style = LastStyle) { FileAppend "...error style " . Style . " is same like last style " LastStyle . "`n", "balance.log" sleep 100 Send "{Down}" ControlFocus "MAGIC_GDT1","Salamander Factory" sleep 100 Style := "" LastStyle := "" sleep 100 Continue } if(Style = "24-TG"){ FileAppend "...end" . "`n", "balance.log" Break } sleep 100 sleep 100 LastStyle := Style WaitControlExist("Button4") Sleep 100 ControlFocus "Button4","Salamander Factory" ControlClick "Button4","Salamander Factory","Transaction" Sleep 100 Send "{TAB 5}" Sleep 100 Send "{Right}" Sleep 100 Send "{BS}" Sleep 100 WaitControlExist("Button2") ControlFocus "Button2","Salamander Factory" ;FileAppend "...click Button2/Transaction" . "`n", "balance.log" ControlClick "Button2","Salamander Factory","Transaction" Sleep 100 ;Special Sleep problem here WaitControlExist("CLASS_MDI_CHILD5") ;the balance list WaitControlExist("Print") ;FileAppend "...click Button1/Exit" . "`n", "balance.log" ControlClick "Button1","Salamander Factory","Exit" Sleep 100 WaitControlExist("CLASS_MDI_CHILD1") ControlFocus "CLASS_MDI_CHILD1","Salamander Factory" ;the popup window WaitControlExist("Button1") ;FileAppend "...click Button1/Exit 2" . "`n", "balance.log" ControlClick "Button1","Salamander Factory" Sleep 100 Number++ Send "{Down}" ;FileAppend "...loop end" . "`n", "balance.log" } Sleep 1000 WinKill("Salamander") ;https://www.autohotkey.com/boards/viewtopic.php?t=108577 ControlExist(Control, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="") { try return ControlGetHwnd(Control, WinTitle, WinText, ExcludeTitle, ExcludeText) return 0 } WaitControlExist(Control) { loop { sleep 1000 if ControlExist(Control) { break } } ```
https://www.autohotkey.com/docs/v2/lib/Sleep.htm
Reply
Anonymous
Information Epoch 1746030167
Development is an iterative process.
Home
Notebook
Contact us