Hello all,
It is possible to interrupt ONLY the current hotkey with an escape or other key, without reload, exitApp, which cause losing variables in the autoexecute area? Also, Pause command is not good because I don't want to resume that command (hotkey).
I have a script with a lot of hotkeys, and I want to interrupt at any point only the one which cause the problem, or if I run it by mistake, etc.
Interrupt ONLY the current hotkey from a script
Re: Interrupt ONLY the current hotkey from a script
Hallo,
use this sleep function and stop the current thread, while it sleeps.
use this sleep function and stop the current thread, while it sleeps.
Code: Select all
Global Exit
Return
Esc::Exit := True ;stops the current thread while it sleeps
q::
Loop, 25
{
ToolTip,% "q-thread: " A_Index
Sleep(200)
}
ToolTip
Return
w::
Loop, 20
{
ToolTip,% "w-thread: " A_Index
Sleep(250)
}
ToolTip
Return
Sleep(Time)
{
End:= A_TickCount + Time
While, (S:= End-A_TickCount) > 0
{
IF !Exit
Sleep,S>100?100:S
Else
{
Exit =
Exit
}
}
}
Re: Interrupt ONLY the current hotkey from a script
So the idea is to use the "Sleep(200)" function instead of native built-in "Sleep, 200" function from Autohotkey everywhere in my hotkeys?
Yes, it works and seems to be a good idea! Thank you!
Yes, it works and seems to be a good idea! Thank you!
Re: Interrupt ONLY the current hotkey from a script
The only issue is that when you press "Esc" key anywhere else, it will set the "Exit" variable, etc.
The workaround this seems to have the trigger key inside the function. Something like this, although I'm sure there are more elegant solutions:
Sleep(Time)
End:= A_TickCount + Time
While, (S:= End-A_TickCount) > 0
{
Tooltip, Sleeping %Time% ;%S%
KeyWait, Esc, D T0.01
If (ErrorLevel = 0)
{
tooltip, Stopped!
Exit
}
}
tooltip
}
Keywait does not accept expressions as parameters, and the the trigger key could be a function parameter, too.
The workaround this seems to have the trigger key inside the function. Something like this, although I'm sure there are more elegant solutions:
Sleep(Time)
End:= A_TickCount + Time
While, (S:= End-A_TickCount) > 0
{
Tooltip, Sleeping %Time% ;%S%
KeyWait, Esc, D T0.01
If (ErrorLevel = 0)
{
tooltip, Stopped!
Exit
}
}
tooltip
}
Keywait does not accept expressions as parameters, and the the trigger key could be a function parameter, too.
Re: Interrupt ONLY the current hotkey from a script
Like Windows 10, more elegant, but worse.
For example:The first sleep must be native because a thread exit would leave the Q key hanging.
If you press the Escape button exactly during this first sleep, your elegant sleep function would not notice this.
But the Hotkeystored the exit request to be executed at the next sleep-function.
For example:
Code: Select all
Loop, 100
{
Send, {q Down}
Sleep, 200 ;native built-in Sleep
Send, {q Up}
Sleep(200) ;sleep function with Exit
}
If you press the Escape button exactly during this first sleep, your elegant sleep function would not notice this.
But the Hotkey
Code: Select all
Esc::Exit := True
Who is online
Users browsing this forum: Leonardo_Portela, mikeyww, sachalamp and 205 guests