LShift spammer

Ask gaming related questions (AHK v1.1 and older)
DETERMINED
Posts: 1
Joined: 15 Mar 2018, 10:01

LShift spammer

15 Mar 2018, 10:17

I'd love to have a very simple yet very useful macro for me :
Basically as long as, say caps lock is on, let is spam LShift 10 times per second
Do you think you could make me that macro ? It'd be awesome !
User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

Re: LShift spammer

17 Mar 2018, 08:35

Code: Select all

SetTimer, Check, 0
return

Check:
If (GetKeyState("CapsLock", "T")) {
Send, {LShift}
Sleep 100
}
return 
I am your average ahk newbie. Just.. a tat more cute. ;)
Rohwedder
Posts: 7613
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: LShift spammer

19 Mar 2018, 02:54

Hallo,
1. #Persistent needed.
2. A timer with zero period and Sleep ??
better:

Code: Select all

#Persistent
SetTimer, Check, 100
return

Check:
If (GetKeyState("CapsLock", "T")) {
Send, {LShift}
}
return
User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

Re: LShift spammer

19 Mar 2018, 05:18

Rohwedder wrote:Hallo,
1. #Persistent needed.
2. A timer with zero period and Sleep ??
better:

Code: Select all

#Persistent
SetTimer, Check, 100
return

Check:
If (GetKeyState("CapsLock", "T")) {
Send, {LShift}
}
return
Huh why is persistent required?
And does it make a difference that settimer is at 0 and rather there is sleep under the label? It's the same thing right? :?
I am your average ahk newbie. Just.. a tat more cute. ;)
Rohwedder
Posts: 7613
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: LShift spammer

19 Mar 2018, 06:20

Hallo,
#persistent is required because the script contains only a timer but not hotkeys, hotstrings, or any use of OnMessage() or Gui.
Just try it without!
A Sleep must be made by the currend thread. Waiting within the period of a timer, not!
https://autohotkey.com/docs/misc/Threads.htm
User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

Re: LShift spammer

19 Mar 2018, 06:47

Rohwedder wrote:Hallo,
#persistent is required because the script contains only a timer but not hotkeys, hotstrings, or any use of OnMessage() or Gui.
Just try it without!
A Sleep must be made by the currend thread. Waiting within the period of a timer, not!
https://autohotkey.com/docs/misc/Threads.htm
Huh the script worked fine with my version too? :wtf:
How would the script behave if #persistent was not written? Because I tried both your suggestions and my script and I didn't see a difference.. :?

But does it make a difference whether the sleep was in the timer or the thread in this case? Because it won't execute it again until the thread is finished. Does it like take more resource or something? I didn't think it would make a difference..
I am your average ahk newbie. Just.. a tat more cute. ;)
Rohwedder
Posts: 7613
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: LShift spammer

19 Mar 2018, 07:07

Hallo,
here the script ends immediately without #Persistent.
Compare:

Code: Select all

#Persistent
SetTimer, A, 300
SetTimer, B, 300
Return
A:
	a:=!a
	ToolTip, %a%  %b%
Return
B:
	b:=!b
Return
and

Code: Select all

#Persistent
SetTimer, A, 0
SetTimer, B, 0
Return
A:
	a:=!a
	ToolTip, %a%  %b%
	Sleep, 300
Return
B:
	b:=!b
	Sleep, 300
Return

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 43 guests