Inverse-reversing scrpit

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
chalermla
Posts: 3
Joined: 28 May 2017, 10:42

Inverse-reversing scrpit

28 May 2017, 10:59

Hello. I am trying to create a inverse-reversing vehicle control script. Here is the code I came up with.

Code: Select all

$~s::
	if( GetKeyState("d","p") )
		send {d up}
		send {a down}
	else if( GetKeyState("a","p") )
		send {a up}
		send {d down}
return

$~s up::
	if( GetKeyState("d","p") )
		send {a up}
		send {d down}
	else if( GetKeyState("a","p") )
		send {d up}
		send {a down}
return
But it is not working. Please help.
Rohwedder
Posts: 7645
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Inverse-reversing scrpit

28 May 2017, 12:08

Hallo,
perhaps with braces?
https://autohotkey.com/docs/commands/Block.htm

Code: Select all

$~s::
	if( GetKeyState("d","p") )
	{
		send {d up}
		send {a down}
	}
	else if( GetKeyState("a","p") )
	{
		send {a up}
		send {d down}
	}
return

$~s up::
	if( GetKeyState("d","p") )
	{
		send {a up}
		send {d down}
	}
	else if( GetKeyState("a","p") )
	{
		send {d up}
		send {a down}
	}
return
Guest

Re: Inverse-reversing scrpit

28 May 2017, 14:03

Rohwedder wrote:Hallo,
perhaps with braces?
https://autohotkey.com/docs/commands/Block.htm
Thank you. I have corrected my script to be as followed.

Code: Select all

$~d::
	if( GetKeyState("s","p") )
	{
		send {d up}
		send {a down}
	}
	else if( GetKeyState("w","p") )
	{
		send {a up}
		send {d down}
	}
return

$~d up::
	if( GetKeyState("s","p") )
	{
		send {a up}
		send {d up}
	}
	else if( GetKeyState("w","p") )
	{
		send {d up}
		send {a up}
	}
return



~s::
	if( GetKeyState("d","p") )
	{
		send {d up}
		send {a down}
	}
	else if( GetKeyState("a","p") )
	{
		send {a up}
		send {d down}
	}
return

~s up::
	if( GetKeyState("d","p") )
	{
		send {a up}
		send {d down}
	}
	else if( GetKeyState("a","p") )
	{
		send {d up}
		send {a down}
	}
return




$~a::
	if( GetKeyState("s","p") )
	{
		send {d down}
		send {a up}
	}
	else if( GetKeyState("w","p") )
	{
		send {a down}
		send {d up}
	}
return

$~a up::
	if( GetKeyState("s","p") )
	{
		send {a up}
		send {d up}
	}
	else if( GetKeyState("w","p") )
	{
		send {d up}
		send {a up}
	}
return



~w::
	if( GetKeyState("d","p") )
	{
		send {d down}
		send {a up}
	}
	else if( GetKeyState("a","p") )
	{
		send {a down}
		send {d up}
	}
return

~w up::
	if( GetKeyState("d","p") )
	{
		send {a up}
		send {d down}
	}
	else if( GetKeyState("a","p") )
	{
		send {d up}
		send {a down}
	}
return
And it work ok. The only problem now is when I alternate A and D, the vehicle heading will be stuck in a straight line for just a moment. I have no idea how to fix that problem.
Rohwedder
Posts: 7645
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Inverse-reversing scrpit

29 May 2017, 00:57

Hallo,
I do not know exactly what you want to do, but try this:

Code: Select all

#If GetKeyState("s","p")
	a::d
	d::a
#If
chalermla
Posts: 3
Joined: 28 May 2017, 10:42

Re: Inverse-reversing scrpit

29 May 2017, 08:40

Hello everyone. I have fixed my code. Now it is working perfectly.

Code: Select all

$~d::
	if( GetKeyState("s","p") )
	{
		send {d up}
		send {a down}
	}
	else if( GetKeyState("w","p") )
	{
		send {a up}
		send {d down}
	}
return

$~d up::
	if( GetKeyState("s","p") )
	{
		send {s down}
		send {w up}
	}
	else if( GetKeyState("w","p") )
	{
		send {s up}
		send {w down}
	}
return



~s::
	if( GetKeyState("d","p") )
	{
		send {d up}
		send {a down}
	}
	else if( GetKeyState("a","p") )
	{
		send {a up}
		send {d down}
	}
return

~s up::
	if( GetKeyState("d","p") )
	{
		send {a up}
		send {d down}
	}
	else if( GetKeyState("a","p") )
	{
		send {d up}
		send {a down}
	}
return




$~a::
	if( GetKeyState("s","p") )
	{
		send {d down}
		send {a up}
	}
	else if( GetKeyState("w","p") )
	{
		send {a down}
		send {d up}
	}
return

$~a up::
	if( GetKeyState("s","p") )
	{
		send {s down}
		send {w up}
	}
	else if( GetKeyState("w","p") )
	{
		send {s up}
		send {w down}
	}
return



~w::
	if( GetKeyState("d","p") )
	{
		send {d down}
		send {a up}
	}
	else if( GetKeyState("a","p") )
	{
		send {a down}
		send {d up}
	}
return

~w up::
	if( GetKeyState("d","p") )
	{
		send {a up}
		send {d down}
	}
	else if( GetKeyState("a","p") )
	{
		send {d up}
		send {a down}
	}
return
Thank you all for your help.
chalermla
Posts: 3
Joined: 28 May 2017, 10:42

Re: Inverse-reversing scrpit

30 May 2017, 11:26

Sorry everyone. The code is not working perfectly. I am bad at this.
Rohwedder wrote:Hallo,
I do not know exactly what you want to do, but try this:

Code: Select all

#If GetKeyState("s","p")
	a::d
	d::a
#If
Basically the principle is that A and D should consistently rotate the vehicle heading left and right, not suddenly change when you're in reverse. Like when you want to go forward and turn right you would press W+D, but if you want to go backward and
turn right you would have to press S+A. I would like to change it into S+D.
Thank you for you help.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 374 guests