Simple movement script

Post gaming related scripts
pstn
Posts: 1
Joined: 28 May 2023, 12:24

Simple movement script

Post by pstn » 28 May 2023, 12:36

Hi guys, I'm trying to create a simple movement script. It should hold down "w" the whole time, and alternate holding down a and d for 10 seconds each. However, when I run it, it doesnt touch the w at all, not even for a single tap, A and D do work fine though. Any idea what might be wrong?

Thanks

Code: Select all

Loop
{
    AutoRepeat("w") ;hold w indefinitely
    AutoRepeat("a",10000) ;hold a 10 seconds
    AutoRepeat("d",10000) ;hold d 10 seconds
}

AutoRepeat(Key, Duration:=0, ByRef Active:=True)
{
    End := A_TickCount + Duration
    While, Active And A_TickCount < End
    {
        SendInput, {%Key% DownR}
        Sleep, 30
    }
    SendInput, {%Key% Up}
}
User avatar
boiler
Posts: 17706
Joined: 21 Dec 2014, 02:44

Re: Simple movement script

Post by boiler » 28 May 2023, 12:57

Why do you think a duration of 0 should act as as indefinite? It’s the opposite. Its duration is 0, so it doesn’t execute the loop even once. If you want to hold it down indefinitely, don’t use the function, just execute Send {w down}.
User avatar
Kenzis
Posts: 15
Joined: 01 May 2020, 13:05

Re: Simple movement script

Post by Kenzis » 18 Jun 2023, 17:24

Simple. Press F1 to start holding W, you can change the delay between sending another W with Delay_Before_Send_Again, and set the number to anything you wan't, the time is in Miliseconds. The higher the number is, the more delay there is between another W input. You can also stop sending W, with the use of F2. Cheers :bravo:
Also, you may exit the app using F10.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetBatchLines, -1
#SingleInstance Force

;Starting config for the booleans and Delay before sending another W.
WDown = False
WUp = False
Delay_Before_Send_Again := 100

;This label will repeat all the time while the script is running, it will use the functions based on which boolean is true.
Repeat_label:
If WDown = True
 {
  Toggle_W_Down()
 }
Else
If WUp = True
 {
  Toggle_W_Up()
 }
  Sleep, %Delay_Before_Send_Again%
Goto, Repeat_label

;Set's the corresponding booleans to True and False making you hold W
F1::
WDown = True
WUp = False
Return

;Set's the corresponding booleans to False and True making you stop holding W
F2::
WDown = False
WUp = True
Return

;Function for W to be held Down
 Toggle_W_Down()
     {
      Send, {W Down}
	  Return
     }

;Function for W to be held Up
 Toggle_W_Up()
     {
      Send, {W Up}
	  Return
     }

;Exit's the app using F10
F10::
ExitApp
Post Reply

Return to “Gaming Scripts (v1)”