Page 1 of 1

Autohotkey script for WASD controls

Posted: Fri Nov 17, 2017 3:55 pm
by Shadrach
Hey,
so I've been digging into using Autohotkey to override the game's keys for WASD controls. Shouldn't be a big deal right, except I'm new to AHK and the language is to say the least, obtuse. Plenty documentation but not always easily understandable and *VERY* techy even for me.

EDIT: This is what I've got working at the moment, file attached. In case anyone searching finds this thread.

Pastebin: https://pastebin.com/dKREVpZA


RE: Autohotkey script for WASD controls (need help)

Posted: Fri Nov 17, 2017 4:33 pm
by Redmarkus5
Can we get a Hotkey for Repair Rail please? I'm not seeing it on the list I have.

RE: Autohotkey script for WASD controls (need help)

Posted: Fri Nov 17, 2017 4:43 pm
by BigDuke66
Not helpful at all but I advise to join the board of autohotkey:
https://autohotkey.com/boards/
There is enough traffic and almost 20k members so I'm sure they can help you.

Personally I use the software only for HPS/JTS games and there I use single key stroke only, what you try here is to hold the key to continue the map movement and that surely needs some fine tuning so it runs smooth.
Sorry again for not being helpful.

RE: Autohotkey script for WASD controls (need help)

Posted: Fri Nov 17, 2017 5:18 pm
by Shadrach
Ok thanks Duke, I might as well do that - there are plenty of WASD scripts I found with a bit of Google but it appears TOAW has something about it making things difficult.

@redmarkus4 - you can't override a hotkey unless a key binding already exists in the game. You *might* be able to do it, AHK can automate almost everything, moving the mouse, right-clicking etc, but that's waaay beyond my skills with this at the moment.

RE: Autohotkey script for WASD controls (need help)

Posted: Sat Nov 18, 2017 4:03 am
by 76mm
I've used AutoHotKey a lot for JTS games and like it a lot. I don't have TOAW IV yet, so am not sure that I understand what you are trying to do...it sounds like the WASD keys are already assigned? If so, I was not aware that you can override them, I've never done that.

I've successfully assigned hotkeys to the arrow keys using this format:
Down::Send !ct{Enter} ; Down Arrow - Bottom of Stack

RE: Autohotkey script for WASD controls (need help)

Posted: Sat Nov 18, 2017 7:29 am
by Shadrach
Hey 76,
I'm a total newb to AHK but I think you're supposed to be able to override keys, otherwise there would be little point to it right?

When looking at some examples I found I saw the same syntax you use, but according to the official tutorial, there needs to be at least a comma after the Send, but maybe it's not strictly required?
https://autohotkey.com/docs/Tutorial.htm#s12
https://autohotkey.com/docs/commands/Send.htm

And I think there should be a Return after each command block, at least for when there are several lines? Basically like a function.

But it works like above now, and I think probably only the devs can answer if TOAW has some special code for keyboard input.

Or if someone's experienced it before that simply using "Send, key" doesn't work for AHK to emulate a held down key? I mean, it worked in other applications before I added the IfWinActive directive, holding down A would send 'aaaaaaaaaaaaaaaaaaa'.



RE: Autohotkey script for WASD controls (need help)

Posted: Sat Nov 18, 2017 8:43 am
by 76mm
ORIGINAL: Shadrach
I'm a total newb to AHK but I think you're supposed to be able to override keys, otherwise there would be little point to it right?
Not really--the main point to AHK as far as I am concerned is to add hotkeys, not replace existing ones. You might be able to replace hotkeys, but I have never done it.

The arrow key line I posted works with a JTS game (without any comma), but I should point out that it "sends" a menu command rather than a movement order, so you will need to tweak it somehow.

RE: Autohotkey script for WASD controls (need help)

Posted: Sat Nov 18, 2017 1:37 pm
by Shadrach
So apparently, there is a built-in shortcut for remapping keys, which does a lot of the magic behind-the-scenes. So that explains why the examples I've found uses a shorter syntax.
https://autohotkey.com/docs/misc/Remap.htm

Problem with the remap method is that I also had to map Shift+W, Ctrl+A, Ctrl+D to make the replacement commands work.
But fair enough, the code is at least cleaner and you have more control I guess.

AutoHotkey script for WASD override in TOAW4 below.
Remapped keys in addition (also had to replace Shift+A for some reason):
Shift+W: Weather overlay
Ctrl+A: Air Unit Report
Shift+A: Air Briefing
Shift+D: Dig In

Code: Select all

 #IfWinActive The Operational Art of War
 
 w::Up
 a::Left
 s::Down
 d::Right
 +w::w
 ^a::a
 +a::+a
 +d::d
 
 #IfWinActive
 

RE: Autohotkey script for WASD controls (need help)

Posted: Sat Nov 18, 2017 2:52 pm
by 76mm
Interesting, thanks for this, will take a look when/if I buy the game!