AHK To Work IN-GAME Only

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

Re: AHK To Work IN-GAME Only

12 Oct 2018, 03:54

Ruevil2 wrote:
Aluneth wrote: Okay so this is my code now:

Code: Select all

#MaxThreadsPerHotkey 2
Coordmode, Mouse, Relative
toggle:=false
#If WinActive("ahk_exe Wow.exe")
F2::
toggle:=!toggle		;; << variable for stop loop. (tip: "!" means "no" or "negative")
While (toggle) {	;; << condition of loop.
ControlSend,, 1, ahk_exe Wow.exe
Sleep, 100
SetControlDelay -1
ControlClick, x1263 y560, ahk_exe Wow.exe, , Left, , NA D
Sleep, 100
ControlSend,, 2, ahk_exe Wow.exe
Sleep, 100
}
Return
#If
I've tested it and it didn't work, my mouse corsair when in game I can move it around and mess with it but when I'm outside of the game it goes to the "X" and "Y" I coordinated :eh:
Does the script looks good to you and should work?
It sounds like you are trying to make a bot that will do some actions in-game for you while you use the mouse to complete other tasks on a second monitor. Is this correct?

Edit:
I'm going to assume this is what you mean. A couple problems with this code.

#1: #IfWinActive is the totally wrong thing to use here. The 'active' window is the one that is currently focused. So this will not work on minimized or unfocused windows and will not allow you to use other programs while the bot is running.


#2: ControlClick is very unreliable in games. 90% of games don't use any controls whatsoever. The only upside to using Controlclick is that it has minimal 'mouse takeover'. I suggest adding individual up/down commands with a sleep in between although this may present a problem with your mouse usage on other programs. (See #4 for explanation of why a 'hold down pause' is necessary in most games).

With ControlSend

Code: Select all

ControlClick, x1263 y560, ahk_exe Wow.exe, , Left, , NA D
Sleep, 50
ControlClick, x1263 y560, ahk_exe Wow.exe, , Left, , NA U

#3: SetControlDelay -1, is also a mistake(for most games).
"This avoids holding the mouse button down during the click, which in turn reduces interference from the user's physical movement of the mouse."
This will directly cause problems with your hotkeys being 'read by the game. It has to do with DirectX polling methods for capturing keyboard data and
will cause scripts to 'skip' key presses at random.

See #3 in this post for explanation of 'hold-down pause' and why it is necessary.
https://autohotkey.com/boards/viewtopic ... 7&t=11084

#4: If you have to read pixel colors, you CANNOT run the game minimized. Pixel/image searches are based off of the current screen buffer and does not detect minimized windows at all. There is no way around this as the only data in memory is the current pixel display.


Final Thoughts: Unfortunately, you will probably be banned for this. I know for a fact that Blizzard is detecting AHK bots as far back as 10 years ago, I got warnings when I use to play and bot, I quit during WotLK. If you want to try anyway you need to add some 'humanizing' factors to your code. Vary the pixel location clicked by a small amount, vary sleep times by a small amount, don't click faster or move the mouse faster than a human could, have your bot take small random breaks(like a person would with bio or food).
First of all @eqv
I want to thank you for trying to make this script work and the effort of helping me out, you’ve been very helpful and I learnt some stuff I didn’t knew before, thank you!

@Ruevil2
Yes, I’m trying to make a bot to spam a few skills while I’m doing other things outside of the game.
I understand that it couldn’t work and I did manage to build a macro that will cast this skill without using a mouse so I’m good to go.
The only problem I’m having right now is that the script won’t run more then a few minutes, it just stops working random ally without giving me any error.
I’ve tested it on my second pc and it does work more then a few minutes but end up stopping too in some point, any idea what might cause this behavior?
Ruevil2
Posts: 160
Joined: 14 Jul 2014, 10:39

Re: AHK To Work IN-GAME Only

12 Oct 2018, 08:10

The only problem I’m having right now is that the script won’t run more then a few minutes, it just stops working random ally without giving me any error.
I’ve tested it on my second pc and it does work more then a few minutes but end up stopping too in some point, any idea what might cause this behavior?
I have experienced this as well with WoW. Personally I like to use Traytips to show some sort of information to let me know where the script is in its current runtime. I like these because they don't take focus or stop execution like a msgbox would.

For example, this would tell you which loop your bot was on. Letting you easily know that it is at least running and not frozen for some reason. Sometimes
I will have these show me the contents of important variables, or a percentage complete counter for long running scripts.
Like this: (A_Index holds the count of the current loop)

Code: Select all

Loop, 10
{
    TrayTip, Loop Count, %A_Index%
    Sleep 500
}
Do you mind sharing what you have working so far?
Aluneth
Posts: 14
Joined: 09 Oct 2018, 11:20

Re: AHK To Work IN-GAME Only

12 Oct 2018, 11:32

Ruevil2 wrote:
The only problem I’m having right now is that the script won’t run more then a few minutes, it just stops working random ally without giving me any error.
I’ve tested it on my second pc and it does work more then a few minutes but end up stopping too in some point, any idea what might cause this behavior?
I have experienced this as well with WoW. Personally I like to use Traytips to show some sort of information to let me know where the script is in its current runtime. I like these because they don't take focus or stop execution like a msgbox would.

For example, this would tell you which loop your bot was on. Letting you easily know that it is at least running and not frozen for some reason. Sometimes
I will have these show me the contents of important variables, or a percentage complete counter for long running scripts.
Like this: (A_Index holds the count of the current loop)

Code: Select all

Loop, 10
{
    TrayTip, Loop Count, %A_Index%
    Sleep 500
}
Do you mind sharing what you have working so far?

Code: Select all

#MaxThreadsPerHotkey 2
Coordmode, Mouse, Relative
toggle:=false
#If WinActive("ahk_exe Wow.exe")
F1::
toggle:=!toggle		;; << variable for stop loop. (tip: "!" means "no" or "negative")
While (toggle) {	;; << condition of loop.
ControlSend,, E, ahk_exe Wow.exe
Sleep, 400
ControlSend,, 1, ahk_exe Wow.exe
Sleep, 400
ControlSend,, F, ahk_exe Wow.exe
Sleep, 400
}
Return
#If
This is what I am using right now, do you have any idea what might cause this?
Ruevil2
Posts: 160
Joined: 14 Jul 2014, 10:39

Re: AHK To Work IN-GAME Only

12 Oct 2018, 14:28

Code: Select all

#MaxThreadsPerHotkey 2
Coordmode, Mouse, Relative
toggle:=false
#If WinActive("ahk_exe Wow.exe")
F1::
toggle:=!toggle		;; << variable for stop loop. (tip: "!" means "no" or "negative")
While (toggle) {	;; << condition of loop.
ControlSend,, E, ahk_exe Wow.exe
Sleep, 400
ControlSend,, 1, ahk_exe Wow.exe
Sleep, 400
ControlSend,, F, ahk_exe Wow.exe
Sleep, 400
}
Return
#If
This is what I am using right now, do you have any idea what might cause this?
Personally I wouldn't use the #IfWinActive context at all, it makes it so you can't stop your script without activating WoW first. I prefer to choose hotkeys that just are not used in other programs, my favorites being Alt+1-5.

I slimmed some things that I don't think are necessary, plus added a couple more for testing purposes. Sprinkled in a little random number gen for humanizing clicks.

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
Let me know if this works out any better for you. I haven't played WoW in a long time and some things have probably changed along the way. I didn't see anything that stood out right away as causing the hanging. That may be something to do with Warden(Blizzards anti cheat) detecting robotic behavior and shutting it down but I am hoping the SetKeyDelay command solves the issue. It sounds to me like keys getting 'stuck'('down' is seen but 'up' is missed or vice versa) or 'skipped'(down and up both missed).
Aluneth
Posts: 14
Joined: 09 Oct 2018, 11:20

Re: AHK To Work IN-GAME Only

13 Oct 2018, 05:41

Ruevil2 wrote:

Code: Select all

#MaxThreadsPerHotkey 2
Coordmode, Mouse, Relative
toggle:=false
#If WinActive("ahk_exe Wow.exe")
F1::
toggle:=!toggle		;; << variable for stop loop. (tip: "!" means "no" or "negative")
While (toggle) {	;; << condition of loop.
ControlSend,, E, ahk_exe Wow.exe
Sleep, 400
ControlSend,, 1, ahk_exe Wow.exe
Sleep, 400
ControlSend,, F, ahk_exe Wow.exe
Sleep, 400
}
Return
#If
This is what I am using right now, do you have any idea what might cause this?
Personally I wouldn't use the #IfWinActive context at all, it makes it so you can't stop your script without activating WoW first. I prefer to choose hotkeys that just are not used in other programs, my favorites being Alt+1-5.

I slimmed some things that I don't think are necessary, plus added a couple more for testing purposes. Sprinkled in a little random number gen for humanizing clicks.

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
Let me know if this works out any better for you. I haven't played WoW in a long time and some things have probably changed along the way. I didn't see anything that stood out right away as causing the hanging. That may be something to do with Warden(Blizzards anti cheat) detecting robotic behavior and shutting it down but I am hoping the SetKeyDelay command solves the issue. It sounds to me like keys getting 'stuck'('down' is seen but 'up' is missed or vice versa) or 'skipped'(down and up both missed).
Hey,
Thanks a lot for the script!
I’ve been running it for 2 hours now no issues what so ever, works flawlessly. Will keep updating if the script stops working.

Edit: Script stopped working after 2 hours the first time and second time after an hour, for me at least. My brother who also using this, managed to work for him for 6 hours straight and if he wouldn’t stop it I don’t think it would stop either. This is so weird...

Return to “Ask For Help”

Who is online

Users browsing this forum: aifritz, Geronimo, Google [Bot], Helgef, jkeks, NewberEnerNeeder1, Xtra and 225 guests