Search code examples
autohotkeyaxisaxesjoystickremap

Controlling joystick axes using AutoHotkey


I will be getting a flight stick for Kerbal Space Program soon and was hoping to AHK-ify it, like every other peripheral I use on my computer. I know how to remap the joystick buttons, and how to get readings for the axes of the flight stick and throttle, but I am unsure of how to control the axes virtually using AutoHotkey. I've seen some mentions of libraries integrating with vJoy and other programs, but those look complicated and I haven't figured out how to use them. Is it possible to manipulate joystick axes in pure AHK v1.1?


Solution

  • No, it is not possible to alter how a physical joystick reports using any third party software, let alone AutoHotkey.

    However, X360CE can alter how a game sees an XBox pad, because it inserts a fake XInput DLL into the game folder, so when the game makes XInput calls, it intercepts them.

    Obviously, if the joystick comes with a driver, the software can alter how the stick reports.

    There is, however, a workaround:
    Install Shaul's vJoy, then you can create a fake "virtual" stick.
    You then read the input from the physical stick, and write the (altered) state to the virtual vJoy stick.

    I have written a library called CvJoyInterface which makes accessing vJoy from AHK very simple.

    The problem with this method is that the physical stick is still visible to the game, so you need to force the game to take input from the virtual stick instead of the physical stick. This can be hard, because in the game's bind screen, when you move the physical stick, the game will see that move before the virtual stick, and instead bind to that.

    If you wish to be able to do this kind of remapping without having to resort to coding, I write an AutoHotkey-based app called UCR which can do all this for you.
    UCR also includes a "GameBind" feature, which allows you to insert a delay into all your remappings, so that you can move the stick, THEN click bind in the game, and wait for UCR to move the stick after a delay, so the game only sees the virtual stick move.
    Once you have made all your bindings in-game, turn off GameBind.

    There is a new suite of apps being written called ViGEm, one of the components of which is called HidGuardian. When finished, this should allow us to hide a physical stick from everything except remapping applications such as UCR, enabling us to do proper remapping without having to resort to delaying input etc.