Make Script Run only when holding key

Ask gaming related questions (AHK v1.1 and older)
excision
Posts: 14
Joined: 30 Jun 2017, 06:06

Make Script Run only when holding key

03 Jul 2017, 13:07

so as the title states trying to get a script to only run when holding down say 1Joy6 tried a few different ways but seems script plays through still so what am wanting it to do is run script while button held if i let go of button it fully stops what its doing and goes back to start of script ready for when i press and hold the button again

so this is what it looks like
Spoiler
Rohwedder
Posts: 7622
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Make Script Run only when holding key

04 Jul 2017, 01:38

Hallo,
only a try! I have no joystick, I can't test it.
Please tell if it works or not.

Code: Select all

#NoEnv
SetWorkingDir %A_ScriptDir%
CoordMode, Mouse, Window
SendMode Input
#SingleInstance Force
SetTitleMatchMode 1
SetControlDelay 1
SetWinDelay 0
SetKeyDelay -1
SetMouseDelay -1
SetBatchLines -1
1Joy6::
SetTimer, T1Joy6, 100
LEFTSIDE:
Send {d down}
Sleep, 63
Send {d up}
Sleep, 32
Send {s down}
Sleep, 62
Send {s up}
Send {d down}
Sleep, 16
Send {s down}
Sleep, 50
Send {d up}
Send {s up}
Send {u down}
Send {k down}
Sleep, 80
Send {u up}
Send {k up}
Sleep, 1200
Send {i down}
Sleep, 100
Send {i up}
Send {u down}
Sleep, 100
Send {u up}
Sleep, 50
Send {u down}
Send {i down}
Send {j down}
Sleep, 100
Send {u up}
Send {i up}
Send {j up}
Sleep, 900
Send {u down}
Send {j down}
Sleep, 50
Send {u up}
Send {j up}
Sleep, 50
Send {j down}
Send {k down}
Sleep, 50
Send {j up}
Send {k up}
Sleep, 50
Send {i down}
Send {k down}
Sleep, 50
Send {i up}
Send {k up}
Sleep, 50
Send {i down}
Send {u down}
Sleep, 50
Send {i up}
Send {u up}
Sleep, 50
Send {u down}
Send {i down}
Send {j down}
Sleep, 50
Send {u up}
Send {i up}
Send {j up}
Sleep, 90
SetTimer, T1Joy6, Off
return
T1Joy6:
KeyWait, 1Joy6, T.02
If ErrorLevel
	Return
Reload
excision
Posts: 14
Joined: 30 Jun 2017, 06:06

Re: Make Script Run only when holding key

04 Jul 2017, 02:07

Rohwedder wrote:Hallo,
only a try! I have no joystick, I can't test it.
Please tell if it works or not.

Code: Select all

#NoEnv
SetWorkingDir %A_ScriptDir%
CoordMode, Mouse, Window
SendMode Input
#SingleInstance Force
SetTitleMatchMode 1
SetControlDelay 1
SetWinDelay 0
SetKeyDelay -1
SetMouseDelay -1
SetBatchLines -1
1Joy6::
SetTimer, T1Joy6, 100
LEFTSIDE:
Send {d down}
Sleep, 63
Send {d up}
Sleep, 32
Send {s down}
Sleep, 62
Send {s up}
Send {d down}
Sleep, 16
Send {s down}
Sleep, 50
Send {d up}
Send {s up}
Send {u down}
Send {k down}
Sleep, 80
Send {u up}
Send {k up}
Sleep, 1200
Send {i down}
Sleep, 100
Send {i up}
Send {u down}
Sleep, 100
Send {u up}
Sleep, 50
Send {u down}
Send {i down}
Send {j down}
Sleep, 100
Send {u up}
Send {i up}
Send {j up}
Sleep, 900
Send {u down}
Send {j down}
Sleep, 50
Send {u up}
Send {j up}
Sleep, 50
Send {j down}
Send {k down}
Sleep, 50
Send {j up}
Send {k up}
Sleep, 50
Send {i down}
Send {k down}
Sleep, 50
Send {i up}
Send {k up}
Sleep, 50
Send {i down}
Send {u down}
Sleep, 50
Send {i up}
Send {u up}
Sleep, 50
Send {u down}
Send {i down}
Send {j down}
Sleep, 50
Send {u up}
Send {i up}
Send {j up}
Sleep, 90
SetTimer, T1Joy6, Off
return
T1Joy6:
KeyWait, 1Joy6, T.02
If ErrorLevel
	Return
Reload
thanks alot for the reply will try it out and get back to u fingers crossed :D
excision
Posts: 14
Joined: 30 Jun 2017, 06:06

Re: Make Script Run only when holding key

04 Jul 2017, 04:41

yeah it works perfectly now thanks alot buddy so say if i use 1joy5 as my keybind it would be like this yes ?
1Joy5::
SetTimer, T1Joy5, 100
Rohwedder
Posts: 7622
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Make Script Run only when holding key

04 Jul 2017, 05:02

Hallo.
You also need a new timer:

Code: Select all

T1Joy5:
KeyWait, 1Joy5, T.02
If ErrorLevel
	Return
Reload
But this violent method (Reload) is definitely not suitable for larger scripts!
excision
Posts: 14
Joined: 30 Jun 2017, 06:06

Re: Make Script Run only when holding key

04 Jul 2017, 05:12

only issue ive noticed sometimes when i let go of the button what ever command it was doing say holding down D or A etc it keeps them held down untill i run it again
Rohwedder
Posts: 7622
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Make Script Run only when holding key

04 Jul 2017, 08:55

Hallo,
then make all keys that could be Down, before the Reload, Up:

Code: Select all

1Joy6::
KeyWait, 1Joy6, T.02
If ErrorLevel
	Return
Loop, Parse,% "dijksu" ;all buttons that could be down
	Send, {%A_LoopField% Up}
Reload
excision
Posts: 14
Joined: 30 Jun 2017, 06:06

Re: Make Script Run only when holding key

04 Jul 2017, 10:54

Rohwedder wrote:Hallo,
then make all keys that could be Down, before the Reload, Up:

Code: Select all

1Joy6::
KeyWait, 1Joy6, T.02
If ErrorLevel
	Return
Loop, Parse,% "dijksu" ;all buttons that could be down
	Send, {%A_LoopField% Up}
Reload

thanks alot bud will give that a try see how it pans out if it does same as last 1 but gets rid of any buttons held down it should be 100% sorted thanks again
excision
Posts: 14
Joined: 30 Jun 2017, 06:06

Re: Make Script Run only when holding key

22 Jul 2017, 08:48

still get the same issue of sometimes keys get stuck down when i let go of 1joy6 despite them all been in Loop, Parse,% "wasduijk" ;all buttons that could be down

like sometimes ill let go of 1joy6 and all is fine just but around 40% chance the keys duijk still gets held down
Rohwedder
Posts: 7622
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Make Script Run only when holding key

22 Jul 2017, 11:25

Just make a hotkey special for the up setting of all sticky keys. In my main script it is the control which makes this problem.
excision
Posts: 14
Joined: 30 Jun 2017, 06:06

Re: Make Script Run only when holding key

22 Jul 2017, 12:11

Rohwedder wrote:Just make a hotkey special for the up setting of all sticky keys. In my main script it is the control which makes this problem.
so how would i go about this i would of expected there to be a super simple code for run code only while holding specific key since stuff like razer synapse etc even has this feature ;)

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 66 guests