Jump to: navigation, search

Howto:Reassign keyboard bindings

3,487 bytes added, 21:35, 4 April 2014
Adding/modifying key assignments
In general, the list of keyboard commands is stored in the property tree and is loaded at startup or when the menu option "Debug -> Reload input" is selected. The main list of commands is available in {{Git link|gitorious|fg/fgdata|master|keyboard.xml|pre=$FG_ROOT/}}, but each aircraft can add/change its own bindings through its -set.xml file, and additional [[config file]]s can do the same.
== Adding /modifying key assignments ==Keyboard bindings are usually fairly simple. They consist of a <tt>&lt;key&gt;</tt> node (with a corresponding index), optional <tt>&lt;name&gt;</tt> and <tt>&lt;desc&gt;</tt> nodes, and one or more <tt>&lt;binding&gt;</tt>s. A very simple example is the default for {{key press|Ctrl|V}}:<syntaxhighlight lang="xml"> <key n="22"> <name>Ctrl-V</name> <desc>Select initial view (view 0)</desc> <binding> <command>property-assign</command> <property>/sim/current-view/view-number</property> <value>0</value> </binding> </key></syntaxhighlight> The initial tag (<tt>&lt;key n="22"&gt;</tt>) is used to identify the keycode; see the next section for how to find it for other keys. If this is not specified, FG won't have an accurate view of which key it is supposed to represent. The next two tags, <tt>&lt;name&gt;</tt> and <tt>&lt;desc&gt;</tt>, simply are there to describe the key and its function, respectively. They are not required but might be used for showing keyboard help information or other user-display uses. The <tt>&lt;binding&gt;</tt> tag is the functional aspect that gets executed when the key is pressed. The above example would be equivalent to this Nasal code:<syntaxhighlight lang="nasal">setprop("/sim/current-view/view-number", 0)</syntaxhighlight>For more on bindings and their different commands see the article about them: [[bindings]]. Here's a more complex binding, also from keyboard.xml, for {{key press|/}}: <syntaxhighlight lang="xml"> <key n="47"> <name>/</name> <desc>Open property browser</desc> <binding> <condition> <not> <property>/sim/input/property-key-handler</property> </not> </condition> <command>nasal</command> <script>gui.property_browser()</script> </binding> <binding> <condition> <property>/sim/input/property-key-handler</property> </condition> <command>nasal</command> <script>prop_key_handler.start()</script> </binding> </key></syntaxhighlight> This now has two bindings that execute based on a <tt>&lt;condition&gt;</tt> (see: [[conditions]]). The first executes if the property key handler development extension is ''not'' enabled, the second if it ''is'' enabled. Both execute a Nasal command: one to open the property browser, the other to start capturing keys (which will also open a browser if the user enters and path and hits {{key press|:}}). Another common element is the <tt>&lt;mod-up&gt;</tt> event, which happens when the button is released. For example, the {{key press|S}} key fires the starter only as long as it is held down, via complementary commands on press and release:<syntaxhighlight lang="xml"> <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></syntaxhighlight> Other similar modifiers are the following:* mod-up: release the key* mod-shift: if {{key press|Shift}} is held down during event* mod-ctrl: if {{key press|Ctrl}} is held down during event* mod-alt: if {{key press|Alt}} is held down (rare)* mod-meta: if {{key press|Meta}} is held down (rare)* mod-super: if {{key press|Super}} is held down (very rare)* mod-hyper: if {{key press|Hyper}} is held down (very rare) (FIXME: describe more, esp. interaction with the key code...)
== Finding keycodes ==

Navigation menu