Controlling Xcsoar while flying condor

Moderators: Uros, Tom, OXO

janjansen
Posts: 1094
Joined: Wed Feb 24, 2016 9:26 pm

Controlling Xcsoar while flying condor

Post by janjansen » Wed Mar 27, 2019 3:44 pm

This has come up a few times on Teamspeak, and it turns out its quite easy to control xcsoar while flying condor. All you need is autohotkey:
https://www.autohotkey.com

Then a little script to send keystrokes to xcsoar. Im using this now for testing:

Code: Select all

SetTitleMatchMode 2
DetectHiddenWindows, on

up::
ControlSend,ahk_parent, {Up}, XCSoar
Return

down::
ControlSend,ahk_parent, {Down}, XCSoar
Return

left::
ControlSend,ahk_parent, {Left}, XCSoar
Return

right::
ControlSend,ahk_parent, {Right}, XCSoar
Return
Save that as some file with .ahk extention and double click it.
All that does is send the cursor keys to xcsoar. By default up/down is to change zoom level, and left/right switches pages. Probably all I need.
And this doesnt seem to interfere with forcefeedback.

You can also use the same script to launch, position and resize xcsoar

For instance adding this to the script above (before the key bindings_:

Code: Select all

Run, C:\xcsoar\xcsoar.exe
WinWait, XCSoar
WinMove, 1920, 0 
WinMaximize 
Launches xcsoar, waits for it to be loaded, moves it to the right monitor and maximizes it.

User avatar
jcomm
Posts: 252
Joined: Mon May 16, 2005 12:51 am

Re: Controlling Xcsoar while flying condor

Post by jcomm » Thu Mar 28, 2019 3:49 pm

Thums Up!
José Oliveira
Hey you Chicks flying bricks....
Come Fly Gliders ! Be Outsiders!

Marpilot
Posts: 71
Joined: Thu Aug 16, 2018 2:40 am

Re: Controlling Xcsoar while flying condor

Post by Marpilot » Wed Apr 10, 2019 11:46 pm

Great! I was looking just for it !
Will test soon :)
Thanks you very much.
(M2K)

Marpilot
Posts: 71
Joined: Thu Aug 16, 2018 2:40 am

Re: Controlling Xcsoar while flying condor

Post by Marpilot » Sat Apr 13, 2019 6:00 pm

Works fine!
Another useful keystroke would be MCready settings +-0.1 by SHIFT+arrUP, SHIFT+arrDOWN.
Can you add this to the script?

janjansen
Posts: 1094
Joined: Wed Feb 24, 2016 9:26 pm

Re: Controlling Xcsoar while flying condor

Post by janjansen » Sat Apr 13, 2019 7:17 pm

Not easily. xcsoar by default doesnt have any key bindings for mcready afaik.
You should be able write your own by creating an xci, but its not straight forward, and I havent gotten it working yet.

If anyone wants to try, this may help:
https://xcsoar.fandom.com/wiki/Advanced:Input

And in the developer manual on page 41:
https://download.xcsoar.org/releases/6. ... manual.pdf

it describes an event
MacCready add, subtract, 0-nn (set value)

But xcsoar seems to ignore my xci completely...

Marpilot
Posts: 71
Joined: Thu Aug 16, 2018 2:40 am

Re: Controlling Xcsoar while flying condor

Post by Marpilot » Sun Apr 14, 2019 1:19 am

Thanks.Will report any progress on this :)

User avatar
Tailspin
Posts: 48
Joined: Sun Dec 13, 2009 3:27 am
Location: San Diego USA
Contact:

Re: Controlling Xcsoar while flying condor

Post by Tailspin » Fri Oct 18, 2019 1:19 am

I've spent a day and a half trying desperately to make this work. No joy.

The weird part is it did work for a while. I could run the script, start Condor, and while I was flying I could change the XCSoar pages and zoom with the left/right, up/down keys.

My script is a copy/paste of janjansen's. I'm a bit suspicious of a Windows 10 update but could find no leads there. Yes I RTFM, and I've Googled my brains out tracking hypothesis for why it might have stopped working. (And, yes, I've restarted the system, reinstalled AutoHotKeys, etc. Several times.)

I've posted in the AutoHotKeys forum, but does anyone here have any ideas?
Image

User avatar
Pit_R
Posts: 1348
Joined: Mon Feb 27, 2006 7:16 pm

Re: Controlling Xcsoar while flying condor

Post by Pit_R » Sat Oct 19, 2019 2:16 pm

Hello
here is mine .ahk script.
As you see it is very similar. For keys I have shift + arrows.
You can try it, who knows. ;)

Code: Select all

SetTitleMatchMode, 2
DetectHiddenWindows, On

>+Up::
WinGet, WinID, ID, XCSoar
ControlSend,ahk_parent, {Up},ahk_id %WinID%  
return

>+Down::
WinGet, WinID, ID, XCSoar
ControlSend,ahk_parent, {Down},ahk_id %WinID%  
return

>+Left::
WinGet, WinID, ID, XCSoar
ControlSend,ahk_parent, {Left},ahk_id %WinID%  
return

>+Right::
WinGet, WinID, ID, XCSoar
ControlSend,ahk_parent, {Right},ahk_id %WinID%  
return
No matter where you go... There you are...

Image
:::: Please use this envelope
Image
to send me a PM.

User avatar
Tailspin
Posts: 48
Joined: Sun Dec 13, 2009 3:27 am
Location: San Diego USA
Contact:

Re: Controlling Xcsoar while flying condor

Post by Tailspin » Sat Oct 19, 2019 4:07 pm

Problem solved.

I created a new script using the contextual: New | AutoHotKey Script menu.

It prepended the following to the new .ahk file:

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.
Now my script works fine.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
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

Run, D:\XCsoar\XCSoar.exe -portrait
WinWait, XCSoar ;

#SingleInstance force

Up::
WinGet, WinID, ID, XCSoar
ControlSend,ahk_parent, {Up},ahk_id %WinID%  
return

Down::
WinGet, WinID, ID, XCSoar
ControlSend,ahk_parent, {Down},ahk_id %WinID%  
return

Left::
WinGet, WinID, ID, XCSoar
ControlSend,ahk_parent, {Left},ahk_id %WinID%  
return

Right::
WinGet, WinID, ID, XCSoar
ControlSend,ahk_parent, {Right},ahk_id %WinID%  
return
Thank you all for your help.
Last edited by Tailspin on Sat Oct 26, 2019 3:20 pm, edited 1 time in total.
Image

Vlovs
Posts: 5
Joined: Thu Aug 19, 2010 4:00 pm

Re: Controlling Xcsoar while flying condor

Post by Vlovs » Sat Oct 19, 2019 7:14 pm

The created file *.xci must be selected in the XCSoar settings and reloaded it. Path in settings:
1. double tab on main screen
2. Config
3. system
4. look
5. language, input
6. Events -> Choose file

Jeffchrisope
Posts: 19
Joined: Sun Oct 06, 2019 11:21 pm

Re: Controlling Xcsoar while flying condor

Post by Jeffchrisope » Mon Oct 28, 2019 12:32 am

If anyone wants to add the ability to change MC in XCSoar (or toggle back and forth between manual and auto MC), yell - I got it working this morning after some experimenting. I currently have it bound to m, a, and z (toggle, increase and decrease). Used an XCI file as noted above.

I wanted more of it working from Condor, so in addition I can open up all the menus and do some page navigation for things like entering/using pan mode, dropping markers, looking at analysis, etc.. Eventually, though, the XCSoar input engine does some odd stuff to AutoHotKey once you have to start tabbing around in the more complicated dialogs, but at that point you’re probably fiddling with stuff you shouldn’t fiddle with in flight.

Anyway, let me know if anyone is interested in seeing the AHK and XCI files I’m using (though it’s all designed to work with a new keypad from Koolertron, https://www.amazon.com/gp/product/B076M ... UTF8&psc=1), which I’ve programmed for all the (odd) hotkeys I’m using. Nice product, wish I had just jumped straight to this rather than the “Condor pad” which was just another numeric keypad.
Image

User avatar
Tailspin
Posts: 48
Joined: Sun Dec 13, 2009 3:27 am
Location: San Diego USA
Contact:

Re: Controlling Xcsoar while flying condor

Post by Tailspin » Mon Oct 28, 2019 4:14 am

Yes indeed. Love to see your AHK script!
Image

MrHerisson
Posts: 222
Joined: Sat Mar 30, 2019 9:11 pm

Re: Controlling Xcsoar while flying condor

Post by MrHerisson » Mon Oct 28, 2019 9:38 am

I use XCSoar on a tablet.....much easier.....unless you use VR of course :wink:
Image

Jeffchrisope
Posts: 19
Joined: Sun Oct 06, 2019 11:21 pm

Re: Controlling Xcsoar while flying condor

Post by Jeffchrisope » Wed Oct 30, 2019 4:51 am

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
Image

Vlovs
Posts: 5
Joined: Thu Aug 19, 2010 4:00 pm

Re: Controlling Xcsoar while flying condor

Post by Vlovs » Sun Nov 03, 2019 1:12 pm

how to assign a button to xcsoar?
You do not have the required permissions to view the files attached to this post.

Post Reply