From 7bed785a4b3857ad2f8d253cb23a3cf9cd65d351 Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Sat, 8 Feb 2020 15:15:45 +0100 Subject: [PATCH] several config file changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed the naming for some options to make them clearer (IMO). Added option to disable monitoring of certain devices’ axes and/or buttons. Made axes/buttons/sensitivity settings for devices optional. --- README.md | 39 ++++++++++++++------------ focus.ahk | 70 +++++++++++++++++++++++++++++------------------ focus.example.ini | 13 +++++---- 3 files changed, 72 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index ef7c7c8..cddcc6e 100644 --- a/README.md +++ b/README.md @@ -67,27 +67,32 @@ If you feel like 100 ms are too slow, set a delay that’s smaller. ``` [devices] -name1="2Joy" -name2="4Joy" -sensitivity1=10 -sensitivity2=1 +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. -`name1` through `nameX` are the names in AHK terms, with `Joy` or `1Joy` being -the first in the list. You’ll 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. +`device1` through `deviceX` are the device names in AHK terms, with `Joy` or +`1Joy` being the first in the list. You’ll 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. -`sensitivity1` through `sensitivityX` is a 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. -Personally I have a very non-aggressive curve on my right stick, so that ones -multiplier is cranked all the way up to `10`. +`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 don’t +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 @@ -99,14 +104,14 @@ not to produce ghost inputs, you might have to increase this. ``` [tools] -path1="C:\Program Files (x86)\EDMarketConnector\EDMarketConnector.exe" -path2="D:\Tools\SSChanger\SSChanger.exe" +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. -`path1` to `pathX` has to be set to the full paths of the tools. +`tool1` to `toolX` has to be set to the full paths of the tools’ executables. `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 diff --git a/focus.ahk b/focus.ahk index 61f0183..4419c7f 100755 --- a/focus.ahk +++ b/focus.ahk @@ -9,8 +9,8 @@ ; detected and (optional, default on) close them again when the ; target is gone. ; -; Make sure your % file file is setup properly. If not you might -; have to go kill the script from Task Manager :) +; Make sure your focus.ini file is setup properly. If not you might +; have to go kill the script from the systray or Task Manager :) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #NoEnv @@ -55,29 +55,39 @@ readConfig(file) { names := [] error := False while (!error) { - IniRead, tmp, % file, devices, name%A_Index% + IniRead, tmp, % file, devices, device%A_Index% if (tmp == "ERROR") error := True else names.push(tmp) } + devcount := names.MaxIndex() senses := [] - error := False - while (!error) { - IniRead, tmp, % file, devices, sensitivity%A_Index% + useAxes := [] + useButtons := [] + loop, %devcount% + { + IniRead, tmp, % file, devices, device%A_Index%sensitivity if (tmp == "ERROR") - error := True - else - senses.push(tmp) + tmp := 1 + senses.push(tmp) + IniRead, tmp, % file, devices, device%A_Index%useAxes + if (tmp == "ERROR") + tmp := True + useAxes.push(tmp) + IniRead, tmp, % file, devices, device%A_Index%useButtons + if (tmp == "ERROR") + tmp := True + useButtons.push(tmp) } - config["devices"] := {"threshold": thold, "names": names, "sensitivities": senses} + config["devices"] := {"threshold": thold, "names": names, "sensitivities": senses, "useAxes": useAxes, "UseButtons": useButtons} ; [tools] IniRead, tkill, % file, tools, kill paths := [] error := False while (!error) { - IniRead, tmp, % file, tools, path%A_Index% + IniRead, tmp, % file, tools, tool%A_Index% if (tmp == "ERROR") error := True else @@ -132,27 +142,33 @@ watchSticks: target := "ahk_exe " config["target"]["name"] ; poll all axes for id, dev in config["devices"]["names"] { - 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] - > config["devices"]["threshold"]) { - ; focus the target! - WinActivate, % target + ; check if axes are enabled for this device + if config["devices"]["useAxes"][id] = True { + 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] + > config["devices"]["threshold"]) { + ; focus the target! + WinActivate, % target + } } } } ; check ALL THE BUTTONS! for id, dev in config["devices"]["names"] { - ; get button count for the device and loop over all of them - buttons := getKeystate(dev "Buttons") - Loop, %buttons% - { - if (getKeyState(dev A_Index)) { - ; focus the target! - WinActivate, % target + ; check if buttons are enabled for this device + if config["devices"]["useButtons"][id] = True { + ; get button count for the device and loop over all of them + buttons := getKeystate(dev "Buttons") + Loop, %buttons% + { + if (getKeyState(dev A_Index)) { + ; focus the target! + WinActivate, % target + } } } } diff --git a/focus.example.ini b/focus.example.ini index 6019a3e..6b94d26 100755 --- a/focus.example.ini +++ b/focus.example.ini @@ -6,13 +6,14 @@ pollingrate=100 targetcheckrate=5000 [devices] -name1="2Joy" -name2="4Joy" -sensitivity1=10 -sensitivity2=1 +device1="2Joy" +device2="4Joy" +device1sensitivity=10 +device5useaxes=False +device6usebuttons=False threshold=5 [tools] -path1="C:\Program Files (x86)\EDMarketConnector\EDMarketConnector.exe" -path2="D:\Tools\SSChanger\SSChanger.exe" +tool1="C:\Program Files (x86)\EDMarketConnector\EDMarketConnector.exe" +tool2="D:\Tools\SSChanger\SSChanger.exe" kill=True