Script Is Working/Running Slower Than It Should

Ask gaming related questions (AHK v1.1 and older)
unplugged
Posts: 3
Joined: 13 Jun 2021, 13:44

Script Is Working/Running Slower Than It Should

13 Jun 2021, 14:40

Code: Select all

;Script made by Ninkjeboi
SetBatchLines -1
;Mouse 4 to strafe

#NoEnv
SendMode, Input
CoordMode, Mouse, Screen

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

strafe(left)
{
moveCount := 20 
sleepInterval := 1
relativeMove := 6


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

$xbutton1::
while getkeystate("xbutton1","P")
{
strafe(true)
strafe(false)
}
return
I am using a script for csgo to do strafes to get faster. In this case when I press the trigger key, the script is working/running slower than it should(not only in the csgo). I couldn't find any solution to this.
Things I tried: Deleting then reinstalling csgo and ahk, turning off Kaspersky, deleting Kaspersky, turning off Windows Defender, setting ahk to high priority.
I also record it https://www.youtube.com/watch?v=H3dOUH6vjyE
I'll be thankful if you guys can help.
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Script Is Working/Running Slower Than It Should

13 Jun 2021, 14:49

Although I did not try the script, it sounds like you are interested in finding out what part of the script is slow. You could use different approaches to discover that. In one approach, you could log each command with a timestamp. In another approach, you could delete a small part of the script to see when the speed appears normal. Another useful approach in testing would be to remove your While loop, and then just call the function one time, to see if it is behaving as you expect. You can also remove your inner loop, since it has 20 iterations, each of which has 2 DLL calls. It seems that with a large number of mouse events and sleeps that you are executing twice in each While iteration, the process might simply not be very fast.
unplugged
Posts: 3
Joined: 13 Jun 2021, 13:44

Re: Script Is Working/Running Slower Than It Should

13 Jun 2021, 15:16

I sent this script to my friend too but he had no problems. I mean it was fast as should be. And I think you will see the problem if you use the script and compare it with my mouse movements and key presses(i forgot to show key presses) in the video. Thanks.
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Script Is Working/Running Slower Than It Should

13 Jun 2021, 15:19

Fair enough. I am just offering some general approaches to the problem. You are now indicating that the same script has different performance on two different computers-- so look for the differences on the computers (e.g., concurrent software, antivirus, etc.) instead of in the script. Just a thought anyway.

My debugging suggestions still stand, if you would like to determine what part of the script is the problem.
unplugged
Posts: 3
Joined: 13 Jun 2021, 13:44

Re: Script Is Working/Running Slower Than It Should

14 Jun 2021, 12:18

It's not about the pc specs. I am pretty sure that my pc is fast and good enough. I already tried it on safe mode too. And I don't know many things about ahk (I mean your debugging suggestions)so I would appreciate it if you could explain a little more. The only thing that I can say about ahk is "macro program" that's all.
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Script Is Working/Running Slower Than It Should

14 Jun 2021, 12:32

An example of a shortened script is below. If it works, expand it little by little, testing along the way. That will help you to pinpoint a problem that occurs with the added code.

Code: Select all

XButton1::strafe(true)

strafe(left)
{
 If left
  key := "d", move := 6
 Else
  key := "a", move := -6
 Send {%key% down}
 DllCall("Sleep", "UInt", 20)
 Loop, 2
  mouseXY(move, -move/4), DllCall("Sleep", "UInt", 1)
 Send {%key% up}
}

mouseXY(x, y)
{
 DllCall("mouse_event", uint, 1, int, x, int, y, uint, 0, int, 0)
}
ballarr
Posts: 1
Joined: 24 Jul 2022, 16:15

Re: Script Is Working/Running Slower Than It Should

24 Jul 2022, 16:18

did anyone get the script working again? just wondering I've had the same problem. it seems back in like 2019 this script worked but now it moves too slow and not as fast as it was before. some ppl said it was cuz of a ahk update that made it slow down but idk. ive looked every where on how to fix this and i cant find anything saying they found the problem .
thinkRand
Posts: 44
Joined: 02 Mar 2022, 04:16
Location: Somewhere in Venezuela
Contact:

Re: Script Is Working/Running Slower Than It Should

26 Jul 2022, 12:10

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

About the mouse_event function the msdn says:

"Note This function has been superseded. Use SendInput instead."

Meaby the script is too old.

Also, Does anyone know if you can put the types in that way? I think that it should be

DllCall("mouse_event","uint",1,"int",x,"int",y,"uint",0,"int",0)
Discord: thinkRand#7433 (UID 681695022600814642)
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Script Is Working/Running Slower Than It Should

26 Jul 2022, 13:55

DllCall:
Deprecated: When specifying an argument type or return type that does not contain a space or asterisk, the quotes around it may be omitted. For example, Str can be used in place of "Str" and CDecl in place of "CDecl". This is not recommended for use in new scripts.
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Script Is Working/Running Slower Than It Should

26 Jul 2022, 16:52

Try:

Code: Select all

#NoEnv
SetBatchLines -1

xbutton1::
    while getkeystate("xbutton1","P")
        strafe(1), strafe(0)
return

strafe(left) {
    static moveCount := 20, sleepInterval := 1, relativeMove := 6
    key := left ? ("d", move := relativeMove) : ("a", move := -relativeMove)
    SendInput, {%key% down}
    DllCall("Sleep", "UInt", 20)
    Loop, %moveCount%
        DllCall("mouse_event",uint,1,int,move,int,-(move/4),uint,0,int,0), DllCall("Sleep", "UInt", sleepInterval)
    SendInput, {%key% up}
}
return

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 49 guests