AHK script to raise/focus a program automatically on joystick input. Also autostarts/-closes tools based on that program being run.
Find a file
alterNERDtive 59d63e42b0
Now watches for process instead of window
Deciding whether or not a tool is already up by a window existing fails
if the tool is started, but hasn’t created a window yet. This is not an
issue if watching for the _process_ to pop up.

Ideally this would also close processes instead of windows when the
watched game goes down, but killing a process from AHK sadly is
ungraceful, unlike closing a window.
2022-09-09 18:31:09 +02:00
CHANGELOG.md Now watches for process instead of window 2022-09-09 18:31:09 +02:00
focus.ahk Now watches for process instead of window 2022-09-09 18:31:09 +02:00
focus.example.ini several config file changes 2020-02-08 15:15:45 +01:00
LICENSE quick&dirty, get it up there … 2020-02-06 14:43:41 +01:00
README.md axis monitoring now watches for changes instead of absolute 2021-01-19 13:18:53 +01:00

AHK Script to Focus a Program Automatically on Joystick Input

Personally Im using it for Elite: Dangerous, but its generic in nature and you can use it for whatever thing you want.

I made it as a replacement for ED:Runner because that a) needs to be run as Admin and I dont like that and b) it kept randomly and silently crashing on me, defeating its purpose.

Features

  • runs in the background and watches for the configured application
  • starts tools you need with the application when its up
  • (optional) kills the tools again when its down
  • when its up, watches configured devices for input and focuses the application if you move any of the axes or hit a button

Requirements

Running from Source

If you have AutoHotKey (1.1.x) installed, you can just run the script from source. Obviously needs AutoHotKey installed.

Using the Executable

If you dont want to install AutoHotKey and/or want something that “just works”, there is a compiled .exe on the releases page.

Settings

Before running the script for the first time, you need to create a focus.ini file or rename the included focus.example.ini to that. It contains my personal settings if you want to go off those as a base. Which is exactly what Ill be doing here to explain things.

Target Application

[target]
name="EliteDangerous64.exe"

The name of the executable the script should be monitoring for. In case of Elite: Dangerous, that is EliteDangerous64.exe.

Polling Rates

[polling]
pollingrate=100
targetcheckrate=5000

pollingrate (in ms) here is the interval at which to check for input on the configured devices. targetcheckrate (also in ms) is the rate at which the script will check if the target application is running. This is less time-critical as it will probably take a couple seconds to fully start anyway.

The lower you set the polling rates, the more CPU it will cost to keep the script running in the background but also the snappier it will react to inputs. If you feel like 100ms are too slow, set a delay thats smaller.

Device Settings

[devices]
device1="2Joy"
device2="4Joy"
device1sensitivity=10
device5useaxes=False
device6usebuttons=False
threshold=5

In this section of the config file you are defining the devices the script should be monitoring.

device1 through deviceX are the device names in AHK terms, with Joy or 1Joy being the first in the list. Youll probably have to go through them in sequence to find out which physical device is which number. The ordering MIGHT change after you reboot the system but has been consistent for me so far. It should definitely change if you reboot with one of the devices unplugged. Make sure to number these sequentially as the script will stop looking at the first number thats not set.

deviceXsensitivity is an (optional) multiplier used for the axis inputs of the device with the same number as above. If you do not have set any curves for your device(s), you should probably leave this at 1 for all of them (or just dont put a setting into your config). Personally I have a very non-aggressive curve on my right stick, so that ones multiplier is cranked all the way up to 10.

Similarly, deviceXuseaxes and deviceXusebuttons can be set to False to disable monitoring of certain devices axes or buttons. If you leave this out, it is assumed True.

Last but not least, threshold will be the intensity of input needed on an axis to trigger the script to focus your application. 5 means a 10% movement up or down an axis since the entire range of movement is 0 to 100, with 50 being resting position. If your device is “wobbly” and needs a huge dead zone in order not to produce ghost inputs, you might have to increase this.

Tools Settings

[tools]
tool1="C:\Program Files (x86)\EDMarketConnector\EDMarketConnector.exe"
tool2="D:\Tools\SSChanger\SSChanger.exe"
kill=True

Here you can set tools the script should run alongside your application.

tool1 to toolX has to be set to the full paths of the tools executables. Make sure to number these sequentially as the script will stop looking at the first number thats not set.

kill is a boolean (True/False) to tell the script whether to kill the tools again after your target application has shut down. If you want them to stay open, just set this to False.

Need Help / Want to Contribute?

If you run into any errors, please look at the devel branch and see if its fixed there already.

If you have no idea what I was saying in that last parargraph and / or it doesnt fix your problem, please file an issue. Thanks! :)

You can also say “Hi” on Discord if that is your thing.