Board index FlightGear Development

Multiple Keyboard Bindings: How does it come together ?

FlightGear is opensource, so you can be the developer. In the need for help on anything? We are here to help you.
Forum rules
Core development is discussed on the official FlightGear-Devel development mailing list.

Bugs can be reported in the bug tracker.

Multiple Keyboard Bindings: How does it come together ?

Postby mhab » Sat Nov 28, 2015 6:47 pm

Hello

Because I ran into some unclear situations with keyboard bindings in case I have multiple bindings defined (concurrently) for one and the same key I tried to figure out how FG handles this.

As of now my understanding is the following:

- each binding is active and stored
--> this I see from /input/keyboard property tree
- conditions are stored as well
- if multiple bindings are fulfilling their condition(s) all of them are fired if the key is pressed ?
--> not sure about this one ??!

My problems:
I have binding #1 coming from keyboard.xml, it calls a nasal script depending on two properties defined as xml-condition tags
I have binding #2 coming from keyboard.xml, it toggles a property by command property-toggle and the same condition as binding #1
I have binding #3 coming from aircraft specific *-set.xml keyboard settings, it calls a different nasal script without conditions

I thought firsthand that the aircraft specific binding wins, and it seems to do so in some cases (other bindings I defined)
In the problem case however the aircraft specific binding doesn't fire ?!

My suspicion now is, that I ran into a bug, because from what I see in /input/keyboard it seems the condition of binding #1+binding #2 was copied to binding #3 despite my intention that binding #3 should fire unconditionally.

What could be a possible workaround so that binding #3 doesn't get the wrong condition ?

Thanks for any insight on this
Mike-DE
mhab
 
Posts: 418
Joined: Thu Apr 18, 2013 11:59 pm
Callsign: D-MIKE
Version: 2020.3.4
OS: Win10

Re: Multiple Keyboard Bindings: How does it come together ?

Postby Necolatis » Mon Nov 30, 2015 5:49 am

The aircraft key does overwrite the keyboard.xml definition. But only the mods that are specified.

Take for example 's' in keyboard.xml:

Code: Select all
 <key n="115">
  <name>s</name>
  <desc>Fire Starter on Selected Engine(s)</desc>
  <binding>
   <command>nasal</command>
   <script>controls.startEngine(1)</script>
  </binding>
  <mod-up>
   <binding>
    <command>nasal</command>
    <script>controls.startEngine(0)</script>
   </binding>
  </mod-up>
 </key>


I tried in the aircraft to overwrite it like this:

Code: Select all
<key n="115">
            <name>s</name>
            <desc>Start engine</desc>
            <binding>
                <command>nasal</command>
                <script>ja37.autostarttimer();</script>
            </binding>
        </key>


That did not work, cause the engine kept dying. So I thought like you that it did not overwrite the key.
Well, it did, but only the key-down-press, not the key-release, which was also defined in keyboard.xml.
So, by overwriting the mod-up also, I got it to work and nothing from keyboard.xml reacts when pressing or letting go of 's' happens now, with this code:

Code: Select all
<key n="115">
            <name>s</name>
            <desc>Start engine</desc>
            <binding>
                <command>nasal</command>
                <script>ja37.autostarttimer();</script>
            </binding>
            <mod-up>
                <!--just to overwrite default s key up -->
                <binding>
                    <command>nasal</command>
                    <script>ja37.noop()</script>
                </binding>
            </mod-up>
        </key>


Notice however that if you have the Walker installed, that it will again overwrite your aircraft keys.

So priority is:

1: Walker
2: Aircraft
3: keyboard.xml

Hope that helps.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: Multiple Keyboard Bindings: How does it come together ?

Postby mhab » Tue Dec 01, 2015 9:38 pm

Hello

Thanks for the feedback.

This is all a bit confusing and I havn't checked the source code about how the bindings are read into the property tree.
If the aircraft overwrites the keyboard bindings only partly, that doesn't sound very convincing.

In my case I was able to solve my problems by avoiding any <condition>...</condition> tags in the binding definitions of the "keyboard.xml" modifications I did.

In order to verify my suspicion described in first post I first added two dummy conditions to the broken aircraft binding, and voila it worked.

Obviously the conditions of the condition tags in "keyboard.xml" are copied to all bindings of same key (and mod ?), including the aircraft specific bindings, which broke the aircraft binding.
By avoiding condition tags in the "keyboard.xml" (and instead testing these within the nasal script) I got everything back to working well.

Mike-DE
mhab
 
Posts: 418
Joined: Thu Apr 18, 2013 11:59 pm
Callsign: D-MIKE
Version: 2020.3.4
OS: Win10


Return to Development

Who is online

Users browsing this forum: No registered users and 10 guests