From 2015f51dde15236f950c8b1bf70a4f6de820ff86 Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Tue, 19 Jan 2021 13:13:15 +0100 Subject: [PATCH 1/2] axis monitoring now watches for changes instead of absolute Will now keep the last axis reading and compare against that, instead of just using a deviation from the center value. That means it will correctly work with axes that do not have a resting position in the center, e.g. physical throttles. Also added the Z, R, U, V axis (aka all AHK axes are now supported) fixes #1 makes #2 less pressing :) --- README.md | 2 +- focus.ahk | 31 +++++++++++++++++++------------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 11b5067..21ddbd8 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ randomly and silently crashing on me, defeating its purpose. * starts tools you need with the application when it’s up * (optional) kills the tools again when it’s down * when it’s up, watches configured devices for input and focuses the application - if you move the X/Y axis or hit a button + if you move any of the axes or hit a button ## Requirements diff --git a/focus.ahk b/focus.ahk index 40021ec..7d6ca3a 100755 --- a/focus.ahk +++ b/focus.ahk @@ -2,7 +2,7 @@ ; This script will raise / focus a target application when you move ; your Joystick/Throttle/Gamepad/whatever axes or hit a button. ; -; I’m using it with twin sticks for Elite Dangerous, but it should be +; I’m using it with twin sticks for Elite Dangerous, but it should be ; generically usable. ; ; It will also start a list of tools if the target application is @@ -25,7 +25,7 @@ setWorkingDir %A_ScriptDir% #Persistent -; check for config file and exit if it doesn’t exist +; check for config file and exit if it doesn’t exist if (!FileExist("focus.ini")) { msgbox, No config file found. Please follow the instructions in the README file. ExitApp, 1 @@ -33,6 +33,7 @@ if (!FileExist("focus.ini")) { ; read focus.ini config := readConfig("focus.ini") +state := {} ; set the target watcher SetTimer, watchTarget, % config["polling"]["targetcheckrate"] @@ -102,8 +103,8 @@ readConfig(file) { return config } -; nothing but jump labels beyond this point, let’s make it explicit -; (AHK v2 will finally get rid of those …) +; nothing but jump labels beyond this point, let’s make it explicit +; (AHK v2 will finally get rid of those …) return ; this one will check for a running target process @@ -114,6 +115,10 @@ return ; 1. stop the stick watching routine ; 2. (optional) stop ALL THE TOOLS watchTarget: + watchTarget() +return +watchTarget() { + global config if (WinExist("ahk_exe " config["target"]["name"])) { ; start stick watcher SetTimer, watchSticks, % config["polling"]["pollingrate"] @@ -138,26 +143,28 @@ watchTarget: } } } -return +} ; this one will check the sticks for input on the X/Y axes or buttons ; if an axis is currently active or a button down, focuses the target program watchSticks: + watchSticks() +return +watchSticks() { + global config, state target := "ahk_exe " config["target"]["name"] ; poll all axes for id, dev in config["devices"]["names"] { ; check if axes are enabled for this device if (config["devices"]["useAxes"][id]) { - for ia, axis in [ "X", "Y" ] { - ; axes are 0-100 - ; -50 means we get a deviation from "0" aka resting state - ; abs() since we don’t care which direction you push the thing - if (abs(getKeyState(dev axis) - 50) - * config["devices"]["sensitivities"][id] + for ia, axis in [ "X", "Y", "Z", "R", "U", "V" ] { + if (abs(getKeyState(dev axis) - state[id][axis]) + * config["devices"]["sensitivities"][id] > config["devices"]["threshold"]) { ; focus the target! WinActivate, % target } + state[id, axis] := getKeyState(dev axis) } } } @@ -176,4 +183,4 @@ watchSticks: } } } -return +} From fd8e396226c231798093aca614a03839a0ec5b3f Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Wed, 20 Jan 2021 08:08:11 +0100 Subject: [PATCH 2/2] CHANGELOG updated --- CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cb99ca..cefaf29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +# v0.2.0 (2021-01-20) + +This release adds proper support for devices beyond just Joysticks, e.g. +physical throttle units. + +## Changed + +* Now watching all available axes, not just X and Y. See below. + +## Fixed + +* Instead of an axis for deviation from the middle (only works with sticks, + really), now watching for a _change_ in axis value. (#1) + # v0.1.1 (2020-08-03) ## Fixed