Conditional Key-Swap for a game. Halp please! Topic is solved

Ask gaming related questions (AHK v1.1 and older)
Zhuikin

Conditional Key-Swap for a game. Halp please!  Topic is solved

08 Sep 2018, 10:06

Hi. I'm rather new to using Autohotkey, so i suspect, that i might be missing something very basic (and hope actually, because i really want this to work).
That said, i did read some of the documentation before asking here and wasn't able to find my answers there.

I'm in need of a script that will conditionally swap two of the Keys for a games control scheme, based on a third key being pressed (or not pressed).
(It's Armored Warfare, a Cry-Engine based game, in case this is relevant).

"a" and "d" used for steering, should be just be a & d most of the time.
However, when "s" is also pressed (going in reverse) i need to make "a" output "d" and vice-versa.

It needs to work on both taps and keys being held, and needs to update, when the situation changes (Which is the part where my actual trouble is).

To make things more complicated, the game does not seem to accept any of the Send(), SendInput(), SendPlay() modes.
So i am limited to using the "basic" redirect (not sure the exact term here)
a::d etc works just fine.

This is what i came up with this far:

Code: Select all

#If GetKeyState("s", "P")

#InputLevel 1
a::d
return

#InputLevel 2
d::a
return

#If
(The #InputLevel stuff was my crutch to separate the output and avoid it just ping-ponging between a and d)

It ALMOST works.
However, while it works, when pressing "s" first and then "a" or "d", it fails to update, when say "a" is already pressed, when i press "s".
It kinda makes sense, since my condition is bound to "s", but then again, it kinda doesn't make sense (or rather i obviously misunderstand the flow of the events) - i expected the whole thing to work kinda like game engines works - being run in regular intervals ala "OnUpdate()". However, it seems to work in a different way.

So to get my question to the point - how to i make sure the condition is updated/re-checked either in regular intervals or whenever something changes?

If you can offer any help, to either fix my script or maybe just telling me how it's actually done.
Thanks!
User avatar
Onimuru
Posts: 107
Joined: 08 Sep 2018, 18:35
Contact:

Re: Conditional Key-Swap for a game. Halp please!

11 Sep 2018, 06:35

Try this

Code: Select all

*$a::
	If GetKeyState("s", "P")
	{
		Send {d Down}
		Keywait, a
		Send {d Up}
		Return
	}
	Send a
	Return

*$d::
	If GetKeyState("s", "P")
	{
		Send {a Down}
		Keywait, d
		Send {a Up}
		Return
	}
	Send a
	Return
You may need to add

Code: Select all

If GetKeyState("Shift", "P")
to allow you to capitalise while chatting or whatever

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: vysmaty and 119 guests