AutoHotKey script to activate game window when you move the joystick while Alt-Tabbed
I know this is a little niche, but hear me out.
I have a dual monitor setup and sometime I like to Alt-Tab to my second monitor while in-game. Usually to look something up, edit market price database, whatever.
Sometimes though, I just get bored in supercruise and tab over to read reddit or whatever. Suddenly the proximity alert starts blaring and I'm heading right into a star or something, or overshooting my target by miles (or millions of miles, because space).
I frantically grab the stick and pull back on throttle but nothing happens. Still tabbed out....
Checking something while docked. Click back to the Elite window. What? No I didn't want to deploy hardpoints! Why is the station shooting at me? etc, etc...
So I made an AHK script. If the Elite window isn't active, moving any axis on the joystick will activate it so you can just straight into the action. This includes pitch and roll (X and Y), throttle (Z), yaw (R) or the POV hat, which I use for lateral thrust.
I know it may seem silly, but it's made my experience just that little bit more awesome. Plus it helps the "immersion". It's like I'm browsing /gonewild on the monitor IN MY EAGLE. Because why wouldn't I?
Anyway, you can copy the code below into a AHK script and away you go. If anyone doesn't know how to use AutoHotKey yell out and I'll run you through it, it's really simple. If anyone
does know how to AHK and can see a way to improve the script please let me know, it's my first one.
Also, I'm using a Thrustmaster T16000M, let me know if the script doesn't work for your joystick.
Code:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
;#Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;This script will activate your game window whenever
;any joystick axis changes. Handy for when you're
;Alt-Tabbed out of the game on your second monitor.
#SingleInstance force
SetFormat, float, 03 ;remove decimals from joystick values
IfWinExist, Elite - Dangerous
{
Loop
{
IfWinActive, Elite - Dangerous
{
;store the throttle axis value
throttle_active := GetKeyState("joyz")
}
IfWinNotActive, Elite - Dangerous
{
Loop
{
;get axis values
GetKeyState, joyx, 1JoyX
GetKeyState, joyy, 1JoyY
GetKeyState, joyr, 1JoyR
GetKeyState, joyp, 1JoyPOV
throttle_notActive := GetKeyState("joyz")
;if any axis changes, activate game window
;joystick X, Y and R axes 'rest' at 50
;joystive POV axis 'rests' at -1
if joyx != 50
{
WinActivate
break
}
if joyy != 50
{
WinActivate
break
}
if joyr != 50
{
WinActivate
break
}
if joyp != -1
{
WinActivate
break
}
if (throttle_active != throttle_notActive)
{
WinActivate
break
}
}
}
}
}
else
MsgBox, Elite - Dangerous window not detected.
return