Cant get this code in loop. Tried a lot of things, no succes :( Topic is solved

Ask gaming related questions (AHK v1.1 and older)
Denis_Miskovic
Posts: 2
Joined: 21 Jul 2021, 11:29

Cant get this code in loop. Tried a lot of things, no succes :(

Post by Denis_Miskovic » 21 Jul 2021, 11:33

Here's the code:

Code: Select all

$MButton::
while getkeystate("MButton","P")
{
strafe(true)
strafe(false)
}
return
And here's the full code that im working with:

Code: Select all

mouseXY(x, y)
{
DllCall("mouse_event",uint,1,int,x,int,y,uint,0,int,0)
}

strafe(left)
{
moveCount := 1
sleepInterval = 1
relativeMove := 3000

if (left)
{
key := ""
move := relativeMove
} else
{
key := ""
move := -relativeMove
}
send {%key% down}
DllCall("Sleep", "UInt", 5)
Loop, %moveCount%
{
mouseXY(move, -(move/4))
DllCall("Sleep", "UInt", sleepInterval)
}
send {%key% up}
}

$MButton::
while getkeystate("MButton","P")
{
strafe(true)
strafe(false)
}
return
Tried many loops and many things but nothing seems to work :( Thanks in advance.

Denis_Miskovic
Posts: 2
Joined: 21 Jul 2021, 11:29

Re: Cant get this code in loop. Tried a lot of things, no succes :(  Topic is solved

Post by Denis_Miskovic » 21 Jul 2021, 11:59

I have found a solution if anyone needs it! I have putted the loop under the while get the state and it seems to work! And for it to be off or on i just putted the hotkey at the bottom of the script that pauses the whole script! I know this is not the best method but it does the job to me! Example that worked for me:

Code: Select all

$Mbutton::
while getkeystate("MButton","P")
Loop
{
strafe(true)
strafe(false)
}
return
$F4:: Pause
[Mod edit: [code][/code] tags added.]

So every ime i press F4 the script stops and every time i press it again it starts again, its the only working method that i found that it works for me! I'm glad if i helped someone :)

Tensai
Posts: 29
Joined: 12 Dec 2019, 14:15

Re: Cant get this code in loop. Tried a lot of things, no succes :(

Post by Tensai » 21 Jul 2021, 12:07

SetTimers are typically a better approach than using loops.
Hope this helps :D :
https://www.autohotkey.com/boards/viewtopic.php?t=19745

Post Reply

Return to “Gaming Help (v1)”