AHK v2 script for XCSoar

Moderators: Uros, Tom, OXO

Post Reply
Posts: 56
Joined: Sat Jun 17, 2017 6:27 am
Location: Tokyo, Japan

AHK v2 script for XCSoar

Post by n98Bk9-NT3 » Mon Sep 25, 2023 10:33 am

Dear all,

Does anybody use AutoHotKey ver2 to control XCSoar while flying?

I got some scripts for ver1.1 from this forum and it works perfectly. But AHK is already ver 2 and I am thinking of moving there.
It may be also good when teaching how to use XCSoar to new comers.

If anybody share your script here, it is highly appreciated.

I am using this script for v1.1 now. But I do not know how it woks. I just modify some key assignment for my purpose.

Code: Select all

#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

; Main top-level cursor behaviors, plus MOST cursor
; movement in submenus

; Main-level numeric "APP keys" (1-4) and submenus (6-0)

; Pulls up the XCSoar quick menu ... utterly busted at the moment

; Enter and Escape - usually works, if you can just get the right thing selected

; Escape:  works well in that it gets me out of broken dialogs that otherwise don't work

; MacCready controls ...

; When AAT, move to next TP

; When AAT, move to previous TP

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.

; Handles piping individual keys to XCSoar
	; 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%

Post Reply