Autohotkey script for WASD controls

The sequel of the legendary wargame with a complete graphics and interface overhaul, major new gameplay and design features such as full naval combat modelling, improved supply handling, numerous increases to scenario parameters to better support large scenarios, and integrated PBEM++.
Post Reply
User avatar
Shadrach
Posts: 767
Joined: Tue Oct 16, 2001 8:00 am
Location: Oslo, Norway
Contact:

Autohotkey script for WASD controls

Post 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

Attachments
TOAW4-Autohotkey.zip
(999 Bytes) Downloaded 63 times
OUW (Order of the Upgrade Wars)
Image
There are folks out there with way too much time on their hands.
- Norm Koger
User avatar
Redmarkus5
Posts: 4454
Joined: Sat Dec 01, 2007 1:59 pm
Location: 0.00

RE: Autohotkey script for WASD controls (need help)

Post by Redmarkus5 »

Can we get a Hotkey for Repair Rail please? I'm not seeing it on the list I have.
WitE2 tester, WitW, WitP, CMMO, CM2, GTOS, GTMF, WP & WPP, TOAW4, BA2
User avatar
BigDuke66
Posts: 2035
Joined: Thu Feb 01, 2001 10:00 am
Location: Terra

RE: Autohotkey script for WASD controls (need help)

Post 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.
User avatar
Shadrach
Posts: 767
Joined: Tue Oct 16, 2001 8:00 am
Location: Oslo, Norway
Contact:

RE: Autohotkey script for WASD controls (need help)

Post 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.
OUW (Order of the Upgrade Wars)
Image
There are folks out there with way too much time on their hands.
- Norm Koger
User avatar
76mm
Posts: 4766
Joined: Sun May 02, 2004 4:26 am
Location: Washington, DC

RE: Autohotkey script for WASD controls (need help)

Post 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
User avatar
Shadrach
Posts: 767
Joined: Tue Oct 16, 2001 8:00 am
Location: Oslo, Norway
Contact:

RE: Autohotkey script for WASD controls (need help)

Post 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'.


OUW (Order of the Upgrade Wars)
Image
There are folks out there with way too much time on their hands.
- Norm Koger
User avatar
76mm
Posts: 4766
Joined: Sun May 02, 2004 4:26 am
Location: Washington, DC

RE: Autohotkey script for WASD controls (need help)

Post 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.
User avatar
Shadrach
Posts: 767
Joined: Tue Oct 16, 2001 8:00 am
Location: Oslo, Norway
Contact:

RE: Autohotkey script for WASD controls (need help)

Post 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
 
OUW (Order of the Upgrade Wars)
Image
There are folks out there with way too much time on their hands.
- Norm Koger
User avatar
76mm
Posts: 4766
Joined: Sun May 02, 2004 4:26 am
Location: Washington, DC

RE: Autohotkey script for WASD controls (need help)

Post by 76mm »

Interesting, thanks for this, will take a look when/if I buy the game!
Post Reply

Return to “The Operational Art of War IV”