on/off long script with one key

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Kasinel
Posts: 5
Joined: 04 Jul 2018, 18:49

on/off long script with one key

04 Jul 2018, 19:00

this is a fragment of mine script, and i have question, how to on/off this script with one key?
this is small fragment of my script, suspen, toggle dont working

PS I want to turn off/on the entire script with one button, this fragment is the longest

Code: Select all

Button:
Toggle := !Toggle

		Loop
		{
			Loop, %Repeat%
			{
			sleep 100
			send %Key%
			sleep 100
			sendinput {LButton down}
			sleep 100
			sendinput {w down}
			sleep 500
			sendinput {w up}
			sendinput {a down}
			sleep 2300
			sendinput {a up}
			sendinput {s down}
			sleep 500
			sendinput {s up}
			sendinput {d down}
			sleep 2300
			sendinput {d up}
			sendinput {LButton up}
			sleep 500
			}
		}
		return
			
Rohwedder
Posts: 7669
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: on/off long script with one key

05 Jul 2018, 01:34

Hallo,
try:

Code: Select all

#MaxThreadsPerHotkey, 2
Button::
#MaxThreadsPerHotkey, 1
If !Toggle := !Toggle
	Reload
Loop
{
	Loop, %Repeat%
	{
		sleep 100
		send %Key%
		sleep 100
		sendinput {LButton down}
		sleep 100
		sendinput {w down}
		sleep 500
		sendinput {w up}
		sendinput {a down}
		sleep 2300
		sendinput {a up}
		sendinput {s down}
		sleep 500
		sendinput {s up}
		sendinput {d down}
		sleep 2300
		sendinput {d up}
		sendinput {LButton up}
		sleep 500
	}
}
return
Of course you have to replace "Button" with a Key!
Last edited by Rohwedder on 05 Jul 2018, 01:39, edited 1 time in total.
User avatar
zliyr
Posts: 36
Joined: 30 Jun 2018, 14:22
Contact:

Re: on/off long script with one key

05 Jul 2018, 01:39

You can try closing the first one and running another, which can launch the first one?

First script:

Code: Select all

*~A::	;replace this with whatever you want
	run, C:\...\Script2.ahk
	ExitApp
	
Second script:

Code: Select all

*~A:: ;replace this with whatever you want
	run, C:\...\Script1.ahk
	ExitApp
Kasinel
Posts: 5
Joined: 04 Jul 2018, 18:49

Re: on/off long script with one key

05 Jul 2018, 13:55

Rohwedder wrote:Hallo,
try:

Code: Select all

#MaxThreadsPerHotkey, 2
Button::
#MaxThreadsPerHotkey, 1
If !Toggle := !Toggle
	Reload
Loop
{
	Loop, %Repeat%
	{
		sleep 100
		send %Key%
		sleep 100
		sendinput {LButton down}
		sleep 100
		sendinput {w down}
		sleep 500
		sendinput {w up}
		sendinput {a down}
		sleep 2300
		sendinput {a up}
		sendinput {s down}
		sleep 500
		sendinput {s up}
		sendinput {d down}
		sleep 2300
		sendinput {d up}
		sendinput {LButton up}
		sleep 500
	}
}
return
Of course you have to replace "Button" with a Key!
this dont stop my script ;/
Kasinel
Posts: 5
Joined: 04 Jul 2018, 18:49

Re: on/off long script with one key

05 Jul 2018, 13:58

zliyr wrote:You can try closing the first one and running another, which can launch the first one?

First script:

Code: Select all

*~A::	;replace this with whatever you want
	run, C:\...\Script2.ahk
	ExitApp
	
Second script:

Code: Select all

*~A:: ;replace this with whatever you want
	run, C:\...\Script1.ahk
	ExitApp
this method be like pause toggle, but i wanna stop script with dont lost my settings
User avatar
zliyr
Posts: 36
Joined: 30 Jun 2018, 14:22
Contact:

Re: on/off long script with one key

05 Jul 2018, 16:13

Kasinel wrote:
zliyr wrote:You can try closing the first one and running another, which can launch the first one?

First script:

Code: Select all

*~A::	;replace this with whatever you want
	run, C:\...\Script2.ahk
	ExitApp
	
Second script:

Code: Select all

*~A:: ;replace this with whatever you want
	run, C:\...\Script1.ahk
	ExitApp
this method be like pause toggle, but i wanna stop script with dont lost my settings
write your settings to a .txt file, https://autohotkey.com/docs/commands/FileAppend.htm
Kasinel
Posts: 5
Joined: 04 Jul 2018, 18:49

Re: on/off long script with one key

06 Jul 2018, 08:34

zliyr wrote:
Kasinel wrote:
zliyr wrote:You can try closing the first one and running another, which can launch the first one?

First script:

Code: Select all

*~A::	;replace this with whatever you want
	run, C:\...\Script2.ahk
	ExitApp
	
Second script:

Code: Select all

*~A:: ;replace this with whatever you want
	run, C:\...\Script1.ahk
	ExitApp
this method be like pause toggle, but i wanna stop script with dont lost my settings
write your settings to a .txt file, https://autohotkey.com/docs/commands/FileAppend.htm
i have settings in my script write in gui like this

Code: Select all

Gui, Add, Text,, Button ON
Gui, Add, Edit, vHotkey, ^1
Gui, Add, Text,, Butto OFF
Gui, Add, Edit, vPOWOFF, ^2
so i dont know how to save this settings
User avatar
zliyr
Posts: 36
Joined: 30 Jun 2018, 14:22
Contact:

Re: on/off long script with one key

06 Jul 2018, 09:21

Kasinel wrote:
zliyr wrote:
Kasinel wrote:
zliyr wrote:You can try closing the first one and running another, which can launch the first one?

First script:

Code: Select all

*~A::	;replace this with whatever you want
	run, C:\...\Script2.ahk
	ExitApp
	
Second script:

Code: Select all

*~A:: ;replace this with whatever you want
	run, C:\...\Script1.ahk
	ExitApp
this method be like pause toggle, but i wanna stop script with dont lost my settings
write your settings to a .txt file, https://autohotkey.com/docs/commands/FileAppend.htm
i have settings in my script write in gui like this

Code: Select all

Gui, Add, Text,, Button ON
Gui, Add, Edit, vHotkey, ^1
Gui, Add, Text,, Butto OFF
Gui, Add, Edit, vPOWOFF, ^2
so i dont know how to save this settings
wait so you want to save what the user wrote in the edit box? to appear when the application re-opens?
have you tried just adding an if statement above each part of the script to check if the program is supposed to be closed or not?
example:

Code: Select all

Stopped := 1

Code: Select all

if(Stopped = 1){
	;your script here
	}
	return

Code: Select all

GuiClose:
	Stopped := 2
	Gui, Show, Hide
	return
Kasinel
Posts: 5
Joined: 04 Jul 2018, 18:49

Re: on/off long script with one key

06 Jul 2018, 17:36

What does it change because it does not solve my problem? Now when I close the script, it minimizes and I have to re-enable it

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Rohwedder and 310 guests