Script Stops Working After A While

Get help with using AutoHotkey and its commands and hotkeys
Aluneth
Posts: 14
Joined: 09 Oct 2018, 11:20

Script Stops Working After A While

15 Oct 2018, 08:32

Hey guys,

So I’m using this script in World of Warcraft, actually me and a few friends of mine.
I’m having this problem with it, the script works for about 2 hours then suddenly stops working.

For my friends this script works for more then 5 hours straight without any issues, any idea why it happens?

A few things I did was,
*Disabled Antivirus
*Ran the script as administrator
*Reinstalled AutoHotKey
*Tested “Corsair Keybord Software” did a few button pressing macros and got the same result

Also when holding “Shift” for a few seconds *for example running in another game* it will stop running then I have to hold shift again and it will resume for 2 seconds and stop again, any idea what might cause this?
A test I did was holding shift and pressing ")'' the outcome is this: )))))))))0000000000000000000000000000000000000000000000

The following script I’m using:

Code: Select all

Coordmode, Mouse, Relative
toggle:=false
SetKeyDelay, 10, 10     ; This forces the ControlSend command to hold each key down for 10ms, increase second parameter to increase reliability
Random, , 1234     ; Initiate random number generator for 'humanizing'
Random, RndNum , 10, 1000    ; Generate first random number between 10-1000(10ms-1second)

!1::     ; ! means Alt when defining hotkeys, ie. Alt+1
    toggle:=!toggle		;; << variable for stop loop. (tip: "!" means "no" or "negative")
    While (toggle) {	;; << condition of loop.
    	Random, RndNum , 10, 1000
        ControlSend, , E, ahk_exe Wow.exe,,,
        Sleep, %RndNum%
        Random, RndNum , 10, 1000
        ControlSend, , 1, ahk_exe Wow.exe
        Sleep, %RndNum%
        Random, RndNum , 10, 1000
        ControlSend, , F, ahk_exe Wow.exe
        Sleep, %RndNum%
        TrayTip, Bot, Iteration #%A_Index%     ; This is added simply as an indicator that the bot is still running
    }
Return
Thanks for helping me out!
eqv
Posts: 66
Joined: 18 Sep 2018, 22:17

Re: Script Stops Working After A While

15 Oct 2018, 10:39

Aluneth wrote:
15 Oct 2018, 08:32
Also when holding “Shift” for a few seconds *for example running in another game* it will stop running then I have to hold shift again and it will resume for 2 seconds and stop again, any idea what might cause this?
A test I did was holding shift and pressing ")'' the outcome is this: )))))))))0000000000000000000000000000000000000000000000
From this part it sounds like a case of "sticky keys" (basically, AHK gets confuse a keep hold a button).

I don't have WoW, so I can't test this at all. Try this:

Code: Select all

#MaxThreadsPerHotkey 2
Coordmode, Mouse, Relative
toggle:=false
SetKeyDelay, 10, 10     ; This forces the ControlSend command to hold each key down for 10ms
Random,, 1234     ; Initiate random number generator for 'humanizing'

!1::     ; ! means Alt when defining hotkeys, ie. Alt+1
toggle:=!toggle
While (toggle)
wow("E"), wow("1"), wow("F"), tray(a_index)
Return

;; -------------------------------------------------
wow(a) {
	Random, RN, 10, 1000
		While (getKeyState("Ctrl","P") || getKeyState("Win","P") || getKeyState("Shift","P") || getKeyState("Alt","P"))
		Sleep 5
	ControlSend, , % a, ahk_exe Wow.exe
	Sleep, %RN%
} tray(a) {
	TrayTip, Bot, Iteration #%a%     ; This is added simply as an indicator that the bot is still running
}
It's the same, but added "getKeyState" to check that you aren't holding Ctrl, Win, Shift or Alt while the bot is going to send a key.
(also now added "#MaxThreadsPerHotkey 2" at the top, to make it work like a toggle)

Hope it helps.
Aluneth
Posts: 14
Joined: 09 Oct 2018, 11:20

Re: Script Stops Working After A While

15 Oct 2018, 11:25

eqv wrote:
15 Oct 2018, 10:39
Aluneth wrote:
15 Oct 2018, 08:32
Also when holding “Shift” for a few seconds *for example running in another game* it will stop running then I have to hold shift again and it will resume for 2 seconds and stop again, any idea what might cause this?
A test I did was holding shift and pressing ")'' the outcome is this: )))))))))0000000000000000000000000000000000000000000000
From this part it sounds like a case of "sticky keys" (basically, AHK gets confuse a keep hold a button).

I don't have WoW, so I can't test this at all. Try this:

Code: Select all

#MaxThreadsPerHotkey 2
Coordmode, Mouse, Relative
toggle:=false
SetKeyDelay, 10, 10     ; This forces the ControlSend command to hold each key down for 10ms
Random,, 1234     ; Initiate random number generator for 'humanizing'

!1::     ; ! means Alt when defining hotkeys, ie. Alt+1
toggle:=!toggle
While (toggle)
wow("E"), wow("1"), wow("F"), tray(a_index)
Return

;; -------------------------------------------------
wow(a) {
	Random, RN, 10, 1000
		While (getKeyState("Ctrl","P") || getKeyState("Win","P") || getKeyState("Shift","P") || getKeyState("Alt","P"))
		Sleep 5
	ControlSend, , % a, ahk_exe Wow.exe
	Sleep, %RN%
} tray(a) {
	TrayTip, Bot, Iteration #%a%     ; This is added simply as an indicator that the bot is still running
}
It's the same, but added "getKeyState" to check that you aren't holding Ctrl, Win, Shift or Alt while the bot is going to send a key.
(also now added "#MaxThreadsPerHotkey 2" at the top, to make it work like a toggle)

Hope it helps.
Thank you!
It actually works! :D

I just cached the game when the script stopped working, and even tho that I exited the script and tried to push the buttons, the game won't recognize them as a 'press'
I just kept pressing these buttons and nothing was happening, its the games multi action bar that is stuck (not a script issue, in my opinion).
Until I restarted the game and reloaded the script, and it worked again.
I think what causing this is that the script running in loops without pausing,
what if we could add a pause after for example 4 cycles of loop? pause for 5 seconds, and then again works for another 4 cycles then again pause for 5 seconds.

Thanks again, I appreciate all the help you've given me so far!
eqv
Posts: 66
Joined: 18 Sep 2018, 22:17

Re: Script Stops Working After A While

25 Oct 2018, 11:39

Aluneth wrote:
15 Oct 2018, 11:25
Until I restarted the game and reloaded the script, and it worked again.
I think what causing this is that the script running in loops without pausing,
what if we could add a pause after for example 4 cycles of loop? pause for 5 seconds, and then again works for another 4 cycles then again pause for 5 seconds.
I'm sorry for responding after so long. Adding this at «tray()» will pause for 5 seconds each 4 loops:

Code: Select all

If (Mod(a,4)=0)	;; <<< Each multiple of 4.
Sleep, 5000	;; <<< 5 Seconds (5000 Milliseconds)
So the code will look like this:

Code: Select all

#MaxThreadsPerHotkey 2
Coordmode, Mouse, Relative
toggle:=false
SetKeyDelay, 10, 10     ; This forces the ControlSend command to hold each key down for 10ms
Random,, 1234     ; Initiate random number generator for 'humanizing'

!1::     ; ! means Alt when defining hotkeys, ie. Alt+1
toggle:=!toggle
While (toggle)
wow("E"), wow("1"), wow("F"), tray(A_Index)
Return

;; -------------------------------------------------
wow(a) {
	Random, RN, 10, 1000
		While (getKeyState("Ctrl","P") || getKeyState("Win","P") || getKeyState("Shift","P") || getKeyState("Alt","P"))
		Sleep 5
	ControlSend, , % a, ahk_exe Wow.exe
	Sleep, %RN%
} tray(a) {
	TrayTip, Bot, Iteration #%a%     ; This is added simply as an indicator that the bot is still running
	If (Mod(a,4)=0)
	Sleep, 5000
}
[Note: «A_Index» is a "built-in" variable with the amount of loops]

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], casperharkin, johnneedshelp and 50 guests