Auto Strafe Script?

Ask gaming related questions (AHK v1.1 and older)
Vitze
Posts: 6
Joined: 01 Nov 2015, 10:09

Auto Strafe Script?

01 Nov 2015, 10:13

I would like a script like this, i know this is possible i just don't know how to do it

I move my mouse to the right and it presses D
I move my mouse to the left and it presses A
Last edited by Vitze on 01 Nov 2015, 16:47, edited 1 time in total.
Vitze
Posts: 6
Joined: 01 Nov 2015, 10:09

Re: Auto Strafe Script? (Garry's Mod)

01 Nov 2015, 16:47

anyone?
JJohnston2
Posts: 204
Joined: 24 Jun 2015, 23:38

Re: Auto Strafe Script?

02 Nov 2015, 00:06

What have you tried so far?
User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

Re: Auto Strafe Script?

05 Nov 2015, 10:11

You need to be more specific.
Do you want "absolute" mode or "relative" mode?

Absolute:
A point on your mouse mat is considered "center". If the mouse is to the right of it (even if it is not moving), then D will be held.

Relative:
If the mouse is currently moving right, hold D, else hold nothing.

AFAIK, neither of these are possible by reading the mouse position using regluar AHK commands (ie MouseGetPos)
This is because games do not read the *position* of the cursor, they read mouse "delta" (change in position) information.
If they read position instead of delta, mouse input would stop working when the (hidden) cursor hit the edge of the screen - ie you could not endlessly turn left or right). Absolute mode is much harder to implement than Relative.

What you probably need to achieve this is the windows RawInput API (ie user32.dll\GetRawInputData).
This is not a subject for the novice programmer.
You can find code that uses the DLL calls that you need to make here: https://github.com/evilC/RollMouse/blob ... lmouse.ahk
GS SAHU
Posts: 37
Joined: 29 Sep 2014, 12:18

Re: Auto Strafe Script?

05 Nov 2015, 10:31

Vitze wrote:I would like a script like this, i know this is possible i just don't know how to do it

I move my mouse to the right and it presses D
I move my mouse to the left and it presses A
this code work as you wish.

Code: Select all


while 1
{
	MouseGetPos, x,y
		diff := x -  oldx
		if (diff > 0)
		{
			send, D
			oldx := x
		}
		else if (diff < 0)
		{
			send, A
			oldx := x
		}	
			
		
}
return
Esc::
ExitApp


Last edited by GS SAHU on 05 Nov 2015, 10:48, edited 1 time in total.
User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

Re: Auto Strafe Script?

05 Nov 2015, 10:35

GS SAHU wrote:
Vitze wrote:I would like a script like this, i know this is possible i just don't know how to do it

I move my mouse to the right and it presses D
I move my mouse to the left and it presses A
this code work as you wish.

Code: Select all


while 1
{
	MouseGetPos, x,y
		diff := y -  oldy
		if (diff > 0)
		{
			send, D
			oldy := y
		}
		else if (diff < 0)
		{
			send, A
			oldy := y
		}	
			
		
}
return
Esc::
ExitApp


This code will probably not work properly with games.
You will only be able to turn right until the mouse hits the right edge of the screen.
Many games also keep the mouse cursor in the center of the screen, so it may not work at all.
GS SAHU
Posts: 37
Joined: 29 Sep 2014, 12:18

Re: Auto Strafe Script?

05 Nov 2015, 11:04

evilC wrote:
GS SAHU wrote:
Vitze wrote:I would like a script like this, i know this is possible i just don't know how to do it

I move my mouse to the right and it presses D
I move my mouse to the left and it presses A
this code work as you wish.

Code: Select all


while 1
{
	MouseGetPos, x,y
		diff := y -  oldy
		if (diff > 0)
		{
			send, D
			oldy := y
		}
		else if (diff < 0)
		{
			send, A
			oldy := y
		}	
			
		
}
return
Esc::
ExitApp


This code will probably not work properly with games.
You will only be able to turn right until the mouse hits the right edge of the screen.
Many games also keep the mouse cursor in the center of the screen, so it may not work at all.
i don't know about game interface. sorry , for in code use y in place of x.

Code: Select all

while 1
{
	MouseGetPos, x,y
		diff := x -  oldx
		if (diff > 0)
		{
			send, D
			oldx := x
		}
		else if (diff < 0)
		{
			send, A
			oldx := x
		}	
			
		
}
return
Esc::
ExitApp

User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

Re: Auto Strafe Script?

05 Nov 2015, 13:33

Its not about game interface, its about the way a mouse works.

The script you posted only sends input when the mouse cursor changes position.

You are playing a racing game, and are taking a long right hand corner...

You move the mouse right, you start the turn, the mouse hits the right edge of the screen.

Doh! You cannot turn right any more.

So even in a best case scenario (Game does not mess with mouse cursor), this script cannot possibly work properly.
User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

Re: Auto Strafe Script?

05 Nov 2015, 16:27

I took my existing mouse reading code (Uses the RawInput API) and packaged it into a library, with mouse -> keyboard as the sample code.

The link is here.
http://ahkscript.org/boards/viewtopic.php?f=19&t=10159

Take the sample script, and comment out the static KeyMap line for Arrow Keys and uncomment the line for WSAD.
If you wish only A and D to work (Not W and S), then use the following keymap line: static KeyMap := {l: "a", r: "d"} ; AD
Run the script, hitting F12 toggles on/off mapping of mouse to WSAD

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 61 guests