Help with while loop spammable keys+modifer

Ask gaming related questions
Nessy123
Posts: 3
Joined: 10 Oct 2018, 18:47

Help with while loop spammable keys+modifer

10 Oct 2018, 19:05

Hi I'm trying to figure out how to tweak this script to work with modifers.
At the moment it repeats a key while holding it down, but I can't make it react to any modifers with the same behaviour.

This is what I have:

Code: Select all

$1:: 

   While ( GetKeyState( "1","P" ) ) { 

      Send, {Blind}{1}

      Sleep, 70

   } 

$2:: 

   While ( GetKeyState( "2","P" ) ) { 

      Send, {Blind}{2}

      Sleep, 70

   } 

$3:: 

   While ( GetKeyState( "3","P" ) ) { 

      Send, {Blind}{3}

      Sleep, 70

   } 

$4:: 

   While ( GetKeyState( "4","P" ) ) { 

      Send, {Blind}{4}

      Sleep, 70


   } 




Return
So what I want to achieve is:
I press "1" and hold it down -> it repeats "1" with a 70ms delay in between.
I press and hold "SHIFT" after and while holding "1" and it will instead of sending "1", send "SHIFT+1" with the same delay.
When I let go of "SHIFT" and still hold "1" I want it to send "1" again with the same delay.
and at last have regular "SHIFT+1" to act as above.

Is this possible?
Rohwedder
Posts: 1438
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Help with while loop spammable keys+modifer

12 Oct 2018, 02:23

Hallo,
use the Wildcard: * and a Return after each hotkey:

Code: Select all

$*1::
While GetKeyState(1,"P")
{
	Send, {Blind}1
	Sleep, 70
}
Return
$*2::
While GetKeyState(2,"P")
{
	Send, {Blind}2
	Sleep, 70
}
Return
$*3::
While GetKeyState(3,"P")
{
	Send, {Blind}3
	Sleep, 70
}
Return
$*4::
While GetKeyState(4,"P")
{
	Send, {Blind}4
	Sleep, 70
}
Return
Shorter:

Code: Select all

$*1::
$*2::
$*3::
$*4::
No := SubStr(A_ThisHotkey,3)
SetKeyDelay, 80 ;default Delay: 10 + 70
While GetKeyState(No,"P")
	Send, {Blind}%No%
Return
Nessy123
Posts: 3
Joined: 10 Oct 2018, 18:47

Re: Help with while loop spammable keys+modifer

12 Oct 2018, 05:53

Hallo,
use the Wildcard: * and a Return after each hotkey:

Code: Select all

$*1::
While GetKeyState(1,"P")
{
	Send, {Blind}1
	Sleep, 70
}
Return
$*2::
While GetKeyState(2,"P")
{
	Send, {Blind}2
	Sleep, 70
}
Return
$*3::
While GetKeyState(3,"P")
{
	Send, {Blind}3
	Sleep, 70
}
Return
$*4::
While GetKeyState(4,"P")
{
	Send, {Blind}4
	Sleep, 70
}
Return
Shorter:

Code: Select all

$*1::
$*2::
$*3::
$*4::
No := SubStr(A_ThisHotkey,3)
SetKeyDelay, 80 ;default Delay: 10 + 70
While GetKeyState(No,"P")
	Send, {Blind}%No%
Return

Thank you!

I will test this when I get home, can you explain this:
No := SubStr(A_ThisHotkey,3)
Why the 3?
Rohwedder
Posts: 1438
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Help with while loop spammable keys+modifer

12 Oct 2018, 06:17

Hallo,
to remove the first 2 characters $* from A_ThisHotkey.
E.g.: If A_ThisHotkey = $*1 then becomes No = 1
https://autohotkey.com/docs/Variables.htm#ThisHotkey
https://autohotkey.com/docs/commands/SubStr.htm

By the way, if you want to use Numpad Keys as well, then:

Code: Select all

$*1::
$*Numpad1::
$*2::
$*Numpad2::
$*3::
$*Numpad3::
$*4::
$*Numpad4::
Key := SubStr(A_ThisHotkey,3)
SetKeyDelay, 80 ;default Delay: 10 + 70
While GetKeyState(Key,"P")
	Send, {Blind}{%Key%}
Return
Nessy123
Posts: 3
Joined: 10 Oct 2018, 18:47

Re: Help with while loop spammable keys+modifer

14 Oct 2018, 17:11

Rohwedder

Thank you! The modifiers works, but when I press the buttons without modifiers, they don't fire for some reason in the game.

Edit: IT WORKS, i just had nothing on my actionbars haha, thank you !!

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 17 guests