AHK v2 script for XCSoar

Moderators: Uros, Tom, OXO

Post Reply
n98Bk9-NT3
Posts: 112
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

#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

; 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}")

; When AAT, move to next TP
^!s::SendToXCS("{s}")

; When AAT, move to previous TP
^!x::SendToXCS("{x}")

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
}
Naoki
Image

Post Reply

Who is online

Users browsing this forum: Bing [Bot]