Tailspin wrote: ↑Mon Oct 28, 2019 4:14 am
Yes indeed. Love to see your AHK script!
Okay, I've attached my current AHK file below, along with the XCI file I use to surface the MacCready change functions. As I noted above, this is using a Koolertron keypad (
https://www.amazon.com/gp/product/B076M ... UTF8&psc=1) that works great as one option for surfacing controls for XCSoar. If XCSoar is in portrait, keys 1-4 cause the main menus to appear along the bottom, and the submenu options along the right side. This is very easy to map to keys on the big keypad (along with the u/d/l/r cursor keys, enter, and escape, which all have functions in XCS).
The other control option is to use a joystick, which is also included in the AHK file. I really like using this … but it doesn't work perfectly yet. Here I'm using the POV control on my Sidewinder FFB joystick to serve as the cursor keys, and mapping enter and escape to buttons. I've also mapped a keypad and joystick key/button to 'F1', which pops up the XCS "Quick Menu", which would be REALLY helpful … except there are cursor navigation issues once you're in dialogs. More on that below.
To customize the keypad/keyboard based control part, you obviously have to change what keys/buttons you want mapped to each function. In mine, you'll see lots of ^!1, ^!Up, etc. because I set my Koolertron keypad encodes keystrokes that way (^ is control, ! is alt modifier keys). You can use whatever you want, obviously.
https://www.autohotkey.com/docs/Hotkeys.htm has information on all the ways to specify keys in AHK.
Customizing the joystick is picking which joystick number to use, known that joystick buttons in AHK are specified with <joysticknumber>Joy<buttonnumber>, so on my system, 5Joy2 refers to button 2 on joystick 5. Trial and error will help you figure out what number your particular joystick is with your setup.
The XCI file is loaded in the XCS config for Input (specify the file, than reboot XCS to load it). It's a surprisingly powerful system for surfacing commands.
So … other than being a minor pain to get this setup initially, the problem enters when any non-map page is up - including things like the Task manager screen and the Quick Menu. When these are showing, button routing gets all wonky, and I haven't figured out how to fix it yet. If you look at the AHK script, it is already a little hacky in the function that does the routing as it fires each key at a few targets. For any given key, at any given time, only one of those methods seems to work … so more to learn there. At any rate, this is MOSTLY not too painful, EXCEPT it would be REALLY cool if you could use the Quick Menu from the joystick POV hat to do things like enter Pan mode or the like. So … I'll keep poking at it, but the end result might be we just have to add the additional "important" commands in the XCI (like Pan mode, maybe) and target them directly.
Let me know if anyone has any questions on this. And yeah, I know most folks just run this on another monitor, or on a tablet, and don't care about this, but for me I really want it all working seamlessly in VR (with XCS projected right on top of the existing PDA, even), and it's sooooo close …
AutoHotKey script:
Code: Select all
#InstallKeybdHook
#Persistent
#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.
SetTitleMatchMode, 2
DetectHiddenWindows, On
#SingleInstance force
; Sets up joystick POV/button watcher
SetTimer, WatchJoy, 5
return
; Joystick buttons routed to XCSoar
5Joy2::SendToXCS("{Enter}")
5Joy3::SendToXCS("{Escape}")
5Joy4::SendToXCS("{F1}")
; Main top-level cursor behaviors, plus MOST cursor
; movement in submenus
^!Up::SendToXCS("{Up}")
^!Down::SendToXCS("{Down}")
^!Left::SendToXCS("{Left}")
^!Right::SendToXCS("{Right}")
; Main-level numeric "APP keys" (1-4) and submenus (6-0)
^!1::SendToXCS("{1}")
^!2::SendToXCS("{2}")
^!3::SendToXCS("{3}")
^!4::SendToXCS("{4}")
^!5::SendToXCS("{5}")
^!6::SendToXCS("{6}")
^!7::SendToXCS("{7}")
^!8::SendToXCS("{8}")
^!9::SendToXCS("{9}")
^!0::SendToXCS("{0}")
; Pulls up the XCSoar quick menu ... utterly busted at the moment
^!F1::SendToXCS("{F1}")
; Enter and Escape - usually works, if you can just get the right thing selected
^!e::SendToXCS("{Enter}")
; Escape: works well in that it gets me out of broken dialogs that otherwise don't work
^!k::SendToXCS("{Escape}")
; MacCready controls ...
^!m::SendToXCS("{m}")
^!a::SendToXCS("{a}")
^!z::SendToXCS("{z}")
WatchJoy:
POV := GetKeyState("5JoyPOV") ; Get position of the POV control.
KeyToHoldDownPrev := KeyToHoldDown ; Prev now holds the key that was down before (if any).
; Some joysticks might have a smooth/continous POV rather than one in fixed increments.
; To support them all, use a range:
if (POV < 0) ; No angle to report
KeyToHoldDown := ""
else if (POV > 31500) ; 315 to 360 degrees: Forward
KeyToHoldDown := "Up"
else if POV between 0 and 4500 ; 0 to 45 degrees: Forward
KeyToHoldDown := "Up"
else if POV between 4501 and 13500 ; 45 to 135 degrees: Right
KeyToHoldDown := "Right"
else if POV between 13501 and 22500 ; 135 to 225 degrees: Down
KeyToHoldDown := "Down"
else ; 225 to 315 degrees: Left
KeyToHoldDown := "Left"
if (KeyToHoldDown = KeyToHoldDownPrev) ; The correct key is already down (or no key is needed).
return ; Do nothing.
; Otherwise, release the previous key and press down the new key:
SetKeyDelay -1 ; Avoid delays between keystrokes.
if KeyToHoldDownPrev ; There is a previous key to release.
SendToXCS("{" . KeyToHoldDownPrev . " up}") ; Release it.
if KeyToHoldDown ; There is a key to press down.
SendToXCS("{" . KeyToHoldDown . " down}") ; Press it down.
return
; Handles piping individual keys to XCSoar
SendToXCS(k)
{
; Yes, this is pretty much belt AND suspenders ... and it's still not
; quite enough for all scenarios, due to some quirks in either AHK, XCS, or both
WinGet, WinID, ID, XCSoar
ControlSend, ahk_parent, %k%, ahk_id %WinID%
ControlGet, WinHwnd, Hwnd,,, XCSoar
ControlSend,ahk_parent, %k%,ahk_id %WinHwnd%
return
}
XCI file for the easy MacCready controls:
Code: Select all
mode=default
type=key
data=m
event=MacCready auto toggle
mode=default
type=key
data=a
event=MacCready up
mode=default
type=key
data=z
event=MacCready down