hotkey to stop running script and write variable value to file

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
xnmp
Posts: 88
Joined: 15 Mar 2013 04:46

hotkey to stop running script and write variable value to file

Post 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

highend
Posts: 13327
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: hotkey to stop running script and write variable value to file

Post 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...
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: hotkey to stop running script and write variable value to file

Post 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.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

xnmp
Posts: 88
Joined: 15 Mar 2013 04:46

Re: hotkey to stop running script and write variable value to file

Post 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))
Last edited by xnmp on 19 Oct 2017 11:58, edited 1 time in total.

xnmp
Posts: 88
Joined: 15 Mar 2013 04:46

Re: hotkey to stop running script and write variable value to file

Post 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

Code: Select all

$checkvar = 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

highend
Posts: 13327
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: hotkey to stop running script and write variable value to file

Post 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", &COPYDATA, "Ptr")
	}

	return
}

One of my scripts helped you out? Please donate via Paypal

xnmp
Posts: 88
Joined: 15 Mar 2013 04:46

Re: hotkey to stop running script and write variable value to file

Post by xnmp »

Thank you very much , it's really helpful,i will try it :mrgreen:

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: hotkey to stop running script and write variable value to file

Post by bdeshi »

[/code]
xnmp wrote: in script 1

Code: Select all

$checkvar = 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);
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

xnmp
Posts: 88
Joined: 15 Mar 2013 04:46

Re: hotkey to stop running script and write variable value to file

Post by xnmp »

i see, thank you very much for the help :D

Post Reply