Page 1 of 1

AutoRun / AutoWalk

Posted: 21 Jun 2016, 05:17
by megnatar
How to use:
In most games W is used to "move" forward. Thus when calling this function
it will simulate a W key down. You can call this function from any hotkey in you're
script. Press the key once to move forward, press it again to
stop moving. Clicking the left mouse button or pushing W down also
will stop you're character from moving.

Place this file in you're authotkey library folder. Which is here:
%Userprofile%\documents\AutoHotkey\lib\

Give it the following name:
AutoWalk.ahk

Simply call this function from a hotkey in you're script. For example:

Mbutton::
AutoWalk()
Return

Code: Select all

/*
	How to use.
	In most games W is used to "move" forward. Thus when calling this function
	it will simulate a W key down. You can call this function from any hotkey
	in you're script. Press the key once to move forward, press it again to 
	stop moving. Clicking the left mouse button or press/release W also
	will stop you're character from moving.
	
	Place this file in you're Authotkey library folder. Which is here:
	%Userprofile%\documents\AutoHotkey\lib\
	
	Give it the following name:
	AutoWalk.ahk
	
	Simply call this function from some hotkey in you're script. For example:
	
	~w::
	AutoWalk()
	Return
	
*/
#InstallKeybdHook
#InstallMouseHook

global AnyKey			;Declaring variable AnyKey as global variable. Variables in functions are local to that function.

AutoWalk()
{
	AnyKey:=A_ThisHotkey					;Placing last pressed hotkey in variable AnyKey.
	AnyKey:=StrReplace(AnyKey, "~")			;Remove the tilde character from variable Anykey, for none blocked hotkeys.
	If(AnyKey = "w")						;Check to see if the hotkey is also the w key.
	{
		KeyWait, w, T0.5			;Waiting half a second for w to be physically released.
		If(errorlevel = 1)			;When w is still down after 500ms errorlevel is set to 1. You're probably walking manually.
		{
			KeyWait, w			;Waiting for w key to be released.
			exit				;W is physically released, so we can exit here since movement is stopped.
		}
	}	
	keywait, %AnyKey%							;Waiting for the hotkey to be released.
	If not W_VirtState:=GetKeyState("w")		;When the virtual status of the w key is not down, when W_VirtState is 0. Do whatever comes below.
	{
		SendInput, {w down}						;Virtually pressing w down. Virtual (logical state) is whatever your O.S. thinks the key status is in. Physical is the actual state on you're keyboard.
		keywait, %AnyKey%
		Loop
		{	;When you're hotkey, Lbutton or w key is physically pressed down, variable KeyState will be set to 1. The body of the "if" statement will then execute.
			If(KeyState:=GetKeyState(AnyKey, "P") || KeyState:=GetKeyState("Lbutton", "P") || KeyState:=GetKeyState("w", "P"))
			{
				keywait, %AnyKey%			;Waiting for you're hotkey to be released.
				SendInput, {w up}			;Virtually sending w up. Stop moving.
				break						;Breaking free from the loop.
			}
			sleep, 100			;Sleeping 1/10th of a second each time the loop is iterated. Prevents the function from using to much CPU cycles.
		}						;You can increase the sleep period, but the function will be less responsive.
	}
}
Return

Re: AutoRun / AutoWalk

Posted: 02 Jul 2016, 14:36
by megnatar
Update:
The w key now also can be used as key to toggle autowalk on or off.

Re: AutoRun / AutoWalk

Posted: 09 Oct 2016, 15:53
by Snuffy
Thank you for this. I'm attempting to use it but I keep getting the "Error: Call to nonexistent function." I have it in the folder you specified and also a local directory to the script. Any ideas on what could be going on?

Re: AutoRun / AutoWalk

Posted: 09 Aug 2019, 20:05
by razgriz97
Congratulations, your script is the best I've found by far until now.

But I'm having a minor issue with it.

I'm using XButton2 instead of Mbutton on this

Code: Select all

Mbutton::
AutoWalk()
Return

if I start to use the script (press once the XButton2) and soon after try to manual walk using W my character stops for about a second and then starts to walk again.

I've tried to mess with the code to see if I could solve this, but haven't achieved any success yet.

The game I've been testing this is on Battlefield 4, IDK if this replicates on other games.

You got any ideia how to fix this?

Re: AutoRun / AutoWalk

Posted: 13 Apr 2020, 09:17
by FlowerBridge
Does that work for every game or for specific ones?

Re: AutoRun / AutoWalk

Posted: 15 Apr 2020, 05:06
by megnatar
vespe1398 wrote:
13 Apr 2020, 09:17
Does that work for every game or for specific ones?
I'm writing A new script atm that does autowalk and is configurable, remebers all games and so on. Although it's already posted in the GameScripts section. Please W8 a bit and it will be finished.

To answer you're question. Yes It should.

Re: AutoRun / AutoWalk

Posted: 15 Apr 2020, 05:08
by megnatar
razgriz97 wrote:
09 Aug 2019, 20:05
Congratulations, your script is the best I've found by far until now.

But I'm having a minor issue with it.

I'm using XButton2 instead of Mbutton on this

Code: Select all

Mbutton::
AutoWalk()
Return

if I start to use the script (press once the XButton2) and soon after try to manual walk using W my character stops for about a second and then starts to walk again.

I've tried to mess with the code to see if I could solve this, but haven't achieved any success yet.

The game I've been testing this is on Battlefield 4, IDK if this replicates on other games.

You got any ideia how to fix this?
Sorry for the sloooooow replay. I'm not always here. Or always not here is more like it. Read my comment to Vespe1398 .

Re: AutoRun / AutoWalk

Posted: 23 Apr 2020, 14:14
by Nucleorion
I have edited the function and duplicated it by calling it AutoRun to be able to choose with different keys if we want to run or walk
He editado la funcion y la he duplicado llamandola AutoRun para poder elegir con diferentes teclas si queremos correr o andar

Code: Select all

/*
	How to use.
	In most games W is used to "move" forward. Thus when calling this function
	it will simulate a W key down. You can call this function from any hotkey
	in you're script. Press the key once to move forward, press it again to 
	stop moving. Clicking the left mouse button or press/release W also
	will stop you're character from moving.
	
	Place this file in you're Authotkey library folder. Which is here:
	%Userprofile%\documents\AutoHotkey\lib\
	
	Give it the following name:
	AutoRun.ahk
	
	Simply call this function from some hotkey in you're script. For example:
	
	~w::
	AutoRun()
	Return
	
*/
#InstallKeybdHook
#InstallMouseHook

global AnyKeyRun			;Declaring variable AnyKeyRun as global variable. Variables in functions are local to that function.

AutoRun()
{
	AnyKeyRun:=A_ThisHotkey					;Placing last pressed hotkey in variable AnyKeyRun.
	AnyKeyRun:=StrReplace(AnyKeyRun, "~")			;Remove the tilde character from variable AnyKeyRun, for none blocked hotkeys.
	If(AnyKeyRun = "w")						;Check to see if the hotkey is also the w key.
	{
		KeyWait, w, T0.5			;Waiting half a second for w to be physically released.
		If(errorlevel = 1)			;When w is still down after 500ms errorlevel is set to 1. You're probably walking manually.
		{
			KeyWait, w			;Waiting for w key to be released.
			exit				;W is physically released, so we can exit here since movement is stopped.
		}
	}	
	keywait, %AnyKeyRun%							;Waiting for the hotkey to be released.
	If not W_VirtState:=GetKeyState("w")		;When the virtual status of the w key is not down, when W_VirtState is 0. Do whatever comes below.
	{
		SendInput, {w down}						;Virtually pressing w down. Virtual (logical state) is whatever your O.S. thinks the key status is in. Physical is the actual state on you're keyboard.
		Sleep, 200
		SendInput, {Shift down}			;Virtually sending Shift up. Stop moving.
		keywait, %AnyKeyRun%
		Loop
		{	;When you're hotkey, Lbutton or w key is physically pressed down, variable KeyState will be set to 1. The body of the "if" statement will then execute.
			If(KeyState:=GetKeyState(AnyKeyRun, "P") || KeyState:=GetKeyState("Lbutton", "P") || KeyState:=GetKeyState("w", "P"))
			{
				keywait, %AnyKeyRun%			;Waiting for you're hotkey to be released.
				SendInput, {w up}			;Virtually sending w up. Stop moving.
				Sleep, 200
				SendInput, {Shift up}			;Virtually sending w up. Stop moving.
				break						;Breaking free from the loop.
			}
			sleep, 100			;Sleeping 1/10th of a second each time the loop is iterated. Prevents the function from using to much CPU cycles.
		}						;You can increase the sleep period, but the function will be less responsive.
	}
}
Return
The use is the same as that of the genil code of razgriz97 Save the code in a file called AutoRun.ahk next to AutoWalk.ahk
El uso es igual que el del genial codigo de razgriz97 Guardar el codgio en un archivo llamado AutoRun.ahk junto al AutoWalk.ahk

Code: Select all

j::
AutoWalk()
Return

h::
AutoRun()
Return

Re: AutoRun / AutoWalk

Posted: 13 May 2020, 14:59
by belicn
can you make this work with roblox please?

Re: AutoRun / AutoWalk

Posted: 09 Jun 2020, 13:31
by go1
Regarding AutoWalk only:

In case the author's code does not work,here is simpler version that you can edit yourself if you have enough experience.
This version does not have any gui's so the activation key is the key below right shift and to the left of right control called "AppsKey".

In Detail Explaination Below:

And the only visual indicator that says that script is active is in tooltip in upper left corner,here is small piece of info regarding what is the tooltip in the upper left corner up on activation of the script with AppsKey: 1 = key is pressed P = windows detects the press key.

Code: Select all

#InstallKeyBdHook
#InstallMouseHook
#NoEnv
SetWorkingDir %A_ScriptDir%
CoordMode, Mouse, Window
#SingleInstance Force
SetTitleMatchMode 2
#WinActivateForce
SetBatchLines -1
#MaxHotkeysPerInterval 99999
#maxThreadsPerHotkey, 999999
setKeyDelay, 19, 19
setMouseDelay, 19
warp:=0
;--------------------------- above are autoexecutables that somehow make things work
AppsKey:: ;to the left of right control key
	warp:=!warp
	while (warp=1)
	{
Send {w down}
sleep 10
GetKeyState, state, w
tooltip,%warp%<>%state%,100,100,1 ;this script does not use gui so this is only visual indicator that it is online
;0 = key is not pressed U = windows detects key as not pressed (if different state than those are active then it means opposite of what is described)
	}

if(warp = 0){
Send {w up}
}
return

/::ExitApp ;shuts script down
\::Reload ;resets script from zero

Re: AutoRun / AutoWalk

Posted: 10 Jun 2020, 17:34
by mikerudie
Fantastic script! Thanks so much.

I was curious though, if there's a way to get this to work with inactive windows??

I've tried to modify the code to work with inactive game windows, but I'm not having any luck whatsoever.

Anyone?

Re: AutoRun / AutoWalk

Posted: 04 Sep 2021, 07:04
by owopeachy
Nucleorion wrote:
23 Apr 2020, 14:14
I have edited the function and duplicated it by calling it AutoRun to be able to choose with different keys if we want to run or walk
He editado la funcion y la he duplicado llamandola AutoRun para poder elegir con diferentes teclas si queremos correr o andar

Code: Select all

/*
	How to use.
	In most games W is used to "move" forward. Thus when calling this function
	it will simulate a W key down. You can call this function from any hotkey
	in you're script. Press the key once to move forward, press it again to 
	stop moving. Clicking the left mouse button or press/release W also
	will stop you're character from moving.
	
	Place this file in you're Authotkey library folder. Which is here:
	%Userprofile%\documents\AutoHotkey\lib\
	
	Give it the following name:
	AutoRun.ahk
	
	Simply call this function from some hotkey in you're script. For example:
	
	~w::
	AutoRun()
	Return
	
*/
#InstallKeybdHook
#InstallMouseHook

global AnyKeyRun			;Declaring variable AnyKeyRun as global variable. Variables in functions are local to that function.

AutoRun()
{
	AnyKeyRun:=A_ThisHotkey					;Placing last pressed hotkey in variable AnyKeyRun.
	AnyKeyRun:=StrReplace(AnyKeyRun, "~")			;Remove the tilde character from variable AnyKeyRun, for none blocked hotkeys.
	If(AnyKeyRun = "w")						;Check to see if the hotkey is also the w key.
	{
		KeyWait, w, T0.5			;Waiting half a second for w to be physically released.
		If(errorlevel = 1)			;When w is still down after 500ms errorlevel is set to 1. You're probably walking manually.
		{
			KeyWait, w			;Waiting for w key to be released.
			exit				;W is physically released, so we can exit here since movement is stopped.
		}
	}	
	keywait, %AnyKeyRun%							;Waiting for the hotkey to be released.
	If not W_VirtState:=GetKeyState("w")		;When the virtual status of the w key is not down, when W_VirtState is 0. Do whatever comes below.
	{
		SendInput, {w down}						;Virtually pressing w down. Virtual (logical state) is whatever your O.S. thinks the key status is in. Physical is the actual state on you're keyboard.
		Sleep, 200
		SendInput, {Shift down}			;Virtually sending Shift up. Stop moving.
		keywait, %AnyKeyRun%
		Loop
		{	;When you're hotkey, Lbutton or w key is physically pressed down, variable KeyState will be set to 1. The body of the "if" statement will then execute.
			If(KeyState:=GetKeyState(AnyKeyRun, "P") || KeyState:=GetKeyState("Lbutton", "P") || KeyState:=GetKeyState("w", "P"))
			{
				keywait, %AnyKeyRun%			;Waiting for you're hotkey to be released.
				SendInput, {w up}			;Virtually sending w up. Stop moving.
				Sleep, 200
				SendInput, {Shift up}			;Virtually sending w up. Stop moving.
				break						;Breaking free from the loop.
			}
			sleep, 100			;Sleeping 1/10th of a second each time the loop is iterated. Prevents the function from using to much CPU cycles.
		}						;You can increase the sleep period, but the function will be less responsive.
	}
}
Return
The use is the same as that of the genil code of razgriz97 Save the code in a file called AutoRun.ahk next to AutoWalk.ahk
El uso es igual que el del genial codigo de razgriz97 Guardar el codgio en un archivo llamado AutoRun.ahk junto al AutoWalk.ahk

Code: Select all

j::
AutoWalk()
Return

h::
AutoRun()
Return
this is great, i love it, the only thing i still need is for it to still activate when i press the hotkey while already holding w, for e.g to press w, walk manually, then press the hotkey, release w and continue walking automatically, i just have no idea how to put this in the code :'(

Re: AutoRun / AutoWalk

Posted: 29 Mar 2022, 03:36
by Nucleorion
Yes, I also have to release w and then hit the assigned key for the autowalk. I don't know how to open that change the code to do that

Re: AutoRun / AutoWalk

Posted: 29 Mar 2022, 03:39
by Nucleorion
go1 wrote:
09 Jun 2020, 13:31
Regarding AutoWalk only:

In case the author's code does not work,here is simpler version that you can edit yourself if you have enough experience.
This version does not have any gui's so the activation key is the key below right shift and to the left of right control called "AppsKey".

In Detail Explaination Below:

And the only visual indicator that says that script is active is in tooltip in upper left corner,here is small piece of info regarding what is the tooltip in the upper left corner up on activation of the script with AppsKey: 1 = key is pressed P = windows detects the press key.

Code: Select all

#InstallKeyBdHook
#InstallMouseHook
#NoEnv
SetWorkingDir %A_ScriptDir%
CoordMode, Mouse, Window
#SingleInstance Force
SetTitleMatchMode 2
#WinActivateForce
SetBatchLines -1
#MaxHotkeysPerInterval 99999
#maxThreadsPerHotkey, 999999
setKeyDelay, 19, 19
setMouseDelay, 19
warp:=0
;--------------------------- above are autoexecutables that somehow make things work
AppsKey:: ;to the left of right control key
	warp:=!warp
	while (warp=1)
	{
Send {w down}
sleep 10
GetKeyState, state, w
tooltip,%warp%<>%state%,100,100,1 ;this script does not use gui so this is only visual indicator that it is online
;0 = key is not pressed U = windows detects key as not pressed (if different state than those are active then it means opposite of what is described)
	}

if(warp = 0){
Send {w up}
}
return

/::ExitApp ;shuts script down
\::Reload ;resets script from zero
I don't understand with which key the autowalk is activated with that code

Re: AutoRun / AutoWalk

Posted: 06 Dec 2022, 19:23
by go1
Near your right control and your right alt on keyboard there should be windows key and apps key.