Page 1 of 1
hotkey to stop running script and write variable value to file
Posted: 19 Oct 2017 11:10
by xnmp
i write a xyplorer script to check duplicated files ,i want the script to check when the user press hotkey (like ctrl + j) ,the script will stop running and write some variable's value to a text
is it possible to do that ?
Thanks in advance
Re: hotkey to stop running script and write variable value to file
Posted: 19 Oct 2017 11:39
by highend
Imho not possible (through internal stuff). ESC stops a script but afaik it does that
forcefully.
That doesn't mean that it is impossible at all. A small .ahk / .au3 tool that provides
a hotkey could set a permanent variable that your XY script checks on each
loop. When it recognizes that the variable has changed -> Do what you want
it to do...
Re: hotkey to stop running script and write variable value to file
Posted: 19 Oct 2017 11:42
by bdeshi
You can run the script by an UDC with the CTRL+J hotkey.
Write the in a way so that its "_initialize" toggles a permanent/global variable on start.
And your main script probably already runs in a loop. Put in a condition somewhere in the loop that checks for that variable, if it's set, then your script stops and writes the results etc. (Also reset that var)
Hope that gives you some ideas.
Re: hotkey to stop running script and write variable value to file
Posted: 19 Oct 2017 11:44
by xnmp
highend wrote:Imho not possible (through internal stuff). ESC stops a script but afaik it does that
forcefully.
That doesn't mean that it is impossible at all. A small .ahk / .au3 tool that provides
a hotkey could set a permanent variable that your XY script checks on each
loop. When it recognizes that the variable has changed -> Do what you want
it to do...
Thank you for the help ,i 'm using autohotkey too, can you please tell me how to do that with autohotkey (i'm so glad to see it's possible)
(actually i thought about that ,but i don't know how to make xyplorer read variable value of autohotkey (without using clipboard or read from file))
Re: hotkey to stop running script and write variable value to file
Posted: 19 Oct 2017 11:54
by xnmp
SammaySarkar wrote:You can run the script by an UDC with the CTRL+J hotkey.
Write the in a way so that its "_initialize" toggles a permanent/global variable on start.
And your main script probably already runs in a loop. Put in a condition somewhere in the loop that checks for that variable, if it's set, then your script stops and writes the results etc. (Also reset that var)
Hope that gives you some ideas.
Thank you for the help
from what i understand , i should write permanent variable for script 1 ,for example $checkvar and set value to "1" when i run that script by ctrl + j
and in my main script (script2) , it set $checkvar to "0" on start ,and check that variable in loop ,if value ==1 it stop the script
but i don't know how to make permanent variable for all script like that, can you please tell me how ,something like this
in script 1
in script 2
Code: Select all
global $checkvar = 0 ; //// declare the global variable and set value on start
//in loop
foreach {
if $checkvar == 1 {
// do what ever i want
break;
}
Thanks
Re: hotkey to stop running script and write variable value to file
Posted: 19 Oct 2017 12:01
by highend
You don't need a global, but permanent variable. Check the perm command from the help file
In .ahk it looks like this.
Code: Select all
#NoEnv
;#NoTrayIcon
#Persistent
#SingleInstance force
SetBatchLines, -1
#IfWinActive, ahk_class ThunderRT6FormDC
^j::
Send_WM_COPYDATA("::perm $P_StopScript = 1")
return
#IfWinActive
; ====================================
; = GOTO: FUNCTIONS - Send_WM_COPYDATA
; ====================================
Send_WM_COPYDATA(message) {
WinGet, XYHwnds, List, ahk_class ThunderRT6FormDC
if !(XYHwnds)
return
size := StrLen(message)
if !(A_IsUnicode) {
VarSetCapacity(data, size * 2, 0)
StrPut(message, &data, size, "UTF-16")
} else {
data := message
}
VarSetCapacity(COPYDATA, A_PtrSize * 3, 0)
NumPut(4194305, COPYDATA, 0, "Ptr")
NumPut(size * 2, COPYDATA, A_PtrSize, "UInt")
NumPut(&data, COPYDATA, A_PtrSize * 2, "Ptr")
Loop, %XYHwnds%
{
thisHWND := XYHwnds%A_Index%
result := DllCall("User32.dll\SendMessageW", "Ptr", thisHWND, "UInt", 74, "Ptr", 0, "Ptr", ©DATA, "Ptr")
}
return
}
Re: hotkey to stop running script and write variable value to file
Posted: 19 Oct 2017 12:04
by xnmp
Thank you very much , it's really helpful,i will try it

Re: hotkey to stop running script and write variable value to file
Posted: 19 Oct 2017 12:40
by bdeshi
[/code]
xnmp wrote:
in script 1
in script 2
Code: Select all
global $checkvar = 0 ; //// declare the global variable and set value on start
//in loop
foreach {
if $checkvar == 1 {
// do what ever i want
break;
}
More like
Code: Select all
foreach ($thing, $things) {
if $P_StopScript { break; }
// do things on $thing
}
// things to do after stop
write($your_variable);
Re: hotkey to stop running script and write variable value to file
Posted: 20 Oct 2017 06:41
by xnmp
i see, thank you very much for the help
