Hotkey hold script

Ask gaming related questions (AHK v1.1 and older)
Phenyl
Posts: 13
Joined: 09 Apr 2022, 11:34

Hotkey hold script

Post by Phenyl » 20 Sep 2022, 17:05

Hi.
I found this ahk script for spamming a hotkey once held and stopped once released. Someone developed it for use in SWTR a decade ago. I have applied to an MMORPG. The keys are from 0-9. What do I add if I want to send multiple keys per loop instead of pressing and holding 1, 2, 3, etc. (bound to different mouse keys)? I tried a few things but it didn't work. Thanks for any help.

Code: Select all

*1::
Loop
{
GetKeyState, state, 1, p
if state = U
break
; Otherwise:
Send, 1
Sleep, 25
}
 
*2::
Loop
{
GetKeyState, state, 2, p
if state = U
break
; Otherwise:
Send, {2}
Sleep, 25

Rohwedder
Posts: 7647
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Hotkey hold script

Post by Rohwedder » 21 Sep 2022, 02:05

Hallo,
both send the keys from 0-9 …

Code: Select all

*1::
While, GetKeyState("1","P")
{
	Send,% Mod(A_Index-1, 10)
	Sleep, 25
}
Return
or:

Code: Select all

*1::
While, GetKeyState("1","P")
{
	Send,% SubStr(A_Index-1, 0)
	Sleep, 25
}
Return

Phenyl
Posts: 13
Joined: 09 Apr 2022, 11:34

Re: Hotkey hold script

Post by Phenyl » 24 Sep 2022, 10:25

Rohwedder wrote:
21 Sep 2022, 02:05
Hallo,
both send the keys from 0-9 …

Code: Select all

*1::
While, GetKeyState("1","P")
{
	Send,% Mod(A_Index-1, 10)
	Sleep, 25
}
Return
or:

Code: Select all

*1::
While, GetKeyState("1","P")
{
	Send,% SubStr(A_Index-1, 0)
	Sleep, 25
}
Return
Thank you!

Another question. How can I send a combination of keys? All of my damage skills are numbered 0-9, but that doesn't mean I want to send all 0-9 at once. And some have chains of skills which is why a loop works if bound to one key because it cycles through the chain. For example, one of my rotations is #'s 1, 3, 7, 9, 5. End of rotation. TIA

Rohwedder
Posts: 7647
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Hotkey hold script

Post by Rohwedder » 25 Sep 2022, 02:14

Did you want something like this?

Code: Select all

*1::
For all, KeyComb in ["#1","#3","#7","#9","#5"]
{
	Send,% KeyComb
	Sleep, 25
}
Until, !GetKeyState("1","P")
Return
or if #'s means digits:

Code: Select all

*1::
For all, Digit in [1,3,7,9,5]
{
	Send,% Digit
	Sleep, 25
}
Until, !GetKeyState("1","P")
Return
The Until line is only necessary if the chain is to be ended prematurely with the release of 1.

Phenyl
Posts: 13
Joined: 09 Apr 2022, 11:34

Re: Hotkey hold script

Post by Phenyl » 25 Sep 2022, 11:04

Rohwedder wrote:
25 Sep 2022, 02:14
Did you want something like this?
[/code]or if #'s means digits:

Code: Select all

*1::
For all, Digit in [1,3,7,9,5]
{
	Send,% Digit
	Sleep, 25
}
Until, !GetKeyState("1","P")
Return
The Until line is only necessary if the chain is to be ended prematurely with the release of 1.

It works!!! OMG, it works!! Thank you so much <3 I did so much reading, but there was no way I would have made this myself. Thank you for your help!

Post Reply

Return to “Gaming Help (v1)”