I'm having a little with the SetTimer function.
Basically what I'm trying to achieve, is have this piece of code check if a certain
window pops up, and the act upon it.
I have this piece of code in the autoexecute section. This works until I press a hotkey, then it
just pauses until I reload the script.
That probably makes sense, because the documentation is saying:
Although timers may give the illusion that the script is performing more than one task simultaneously, this is not the case. Instead, timed subroutines are treated just like other threads: they can interrupt or be interrupted by another thread, such as a hotkey subroutine. See Threads for details.
So my question is, is there a(nother) way to keep these timers doing their checks while the code under the hotkey is running ?
I now I could run a second script with the SetTimer functions that I'd like to avoid that if possible.
I hope this makes sense
relevant part:
Code: Select all
SetTimer, CatchErrors, 50
SetTimer, Afdrukformaat, 50
return
CatchErrors:
imagesearch, tsbX, tsbY, 0,0, A_ScreenWidth, A_ScreenHeight, *30 images\taal_sjabloon.png
If ErrorLevel = 0
{
MsgBox, Found !
Send, {Enter}
}
else
{
Tooltip, NOT found !
Sleep, 2000
ToolTip
}
return
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetTitleMatchMode, 2
DetectHiddenWindows, On
Progress,2: CWFF0000 CTFFFFFF W200 zh0 fs12 B1 x1 y800, Starten: ctrl-7 `nReload: ctrl-2 `nAfsluiten: ctrl-0
SetTimer, CatchErrors, 50
SetTimer, Afdrukformaat, 50
return
CatchErrors:
imagesearch, tsbX, tsbY, 0,0, A_ScreenWidth, A_ScreenHeight, *30 images\taal_sjabloon.png
If ErrorLevel = 0
{
MsgBox, Found !
Send, {Enter}
}
else
{
Tooltip, NOT found !
Sleep, 2000
ToolTip
}
return
Afdrukformaat:
imagesearch, adfX, adfY, 0,0, A_ScreenWidth, A_ScreenHeight, *30 images\afdrukformaat.png
if ErrorLevel = 0
{
Searchbutton("afdrukformaat_ja.png", "afdrukformaat (ja) knop")
WinWait, TSI Prod, Afdrukinstellingen, 1
Searchbutton("afdrukinstellingen_ok.png", "afdrukinstellingen (OK) knop")
Searchbutton("alle_paginas_afgedrukt.png", "alle pagina's afgedrukt Venster")
Send, {Enter}
}
return
^0::
MsgBox,,,Emergency keys pressed`, exiting, 2
ExitApp
^2::
Reload
return
^7::
Loop
{
WinActivate, TSI Prod
sleep, 1000
WinMaximize, TSI Prod
WinWaitActive, TSI Prod
InputBox, vPickNR, Pickid, Voer het picknummer in,, 200, 150
if ErrorLevel
{
MsgBox, CANCEL gedrukt. Opnieuw starten met CTRL-7
return
}
InputBox, vColli, Colli, Voer het aantal colli in,, 200, 150,,,,,1
if ErrorLevel
{
MsgBox, CANCEL gedrukt. Opnieuw starten met CTRL-7
return
}
IfWinActive,, Picklijst
{
Send, !na ; close all windows if picklistscreen is already active
Searchbutton("hoofdmenu.png", "Hoofdmenu")
}
Send {F11}
WinWait,, Picklijst, 1
MaxWindow("images\maximize.png", "images\restore_down.png", "Picklijst")
MaxWindow(Filename, Filename2, WindowToWaitFor)
{
Loop
{
; search if the window is maximized, if not maximize it
imagesearch, varX, varY, 0,0, A_ScreenWidth, A_ScreenHeight, *30 %Filename%
if ErrorLevel = 0
{
Click, %varX%, %varY%
Break
}
else
{
; check if the window is already maximized
imagesearch, varX, varY, 0,0, A_ScreenWidth, A_ScreenHeight, *30 %FileName2%
if ErrorLevel = 0
{
Sleep, 1200
Break
}
else
{
WinWait,, %WindowToWaitFor%
continue
}
}
}
}
Send, %vPickNR%{Enter}
sleep, 1500
Searchbutton("allepicken.png", "Alle picken knop")
SearchButton(buttonfile, buttondescription)
{
Loop
{
Sleep, 500
imagesearch, buttonX, buttonY, 0,0, A_ScreenWidth, A_ScreenHeight, *30 images\%buttonfile%
if ErrorLevel = 0
{
Click, %buttonX%, %buttonY%
break
}
else
{
if A_Index = 1
Progress, zh0 fs18 B1, Wacht op %buttondescription%
continue
}
}
Progress, Off ; clear progress text
}
Searchbutton("actualiseren.png", "Actualiseren knop")
Searchbutton("creeren.png", "Crëeren knop")
Searchbutton("handmatige_factuur.png", "handmatige factuur optie")
Searchbutton("uitgaande_factuur.png", "uitgaande factuur scherm")
MaxWindow("images\maximize.png", "images\restore_down.png", "Uitgaande factuur")
Searchbutton("colli_selectie.png", "colli veld")
Send, %vColli%
Searchbutton("toevoegen.png", "Toevoegen knop")
Searchbutton("uitgaande_factuur_ja.png", "uitgaande factuur (ja) knop")
;Searchbutton("pallet_selectie.png", "pallet veld") ;;;;;;;;;;;;;
WinWait, TSI Prod, Systeemmelding
Send, {enter}
WinWaitNotActive, TSI Prod, Uitgaande factuur
;;;;return ;; return van ^7
}