Howto:Reassign keyboard bindings: Difference between revisions

Jump to navigation Jump to search
→‎Finding keycodes: + Subsection headings; +Using the property browser
(+Related: Howto:Add multi-key commands to an aircraft; +- headings)
(→‎Finding keycodes: + Subsection headings; +Using the property browser)
Line 82: Line 82:
As mentioned in keyboard.xml, "regular keycodes go up to 255; special keys start at 256, and can be calculated by adding 256 to the GLUT key value in glut.h."
As mentioned in keyboard.xml, "regular keycodes go up to 255; special keys start at 256, and can be calculated by adding 256 to the GLUT key value in glut.h."


For printable/ASCII keys (e.g. any letter of the alphabet, number, or symbol found on a keyboard), this is simply the ASCII value of the key. [http://home.paulschou.net/tools/xlate/ xlate] is a simple tool that can convert from a letter to appropriate number: enter the letter in <tt><nowiki>[TEXT]</nowiki></tt>, click convert, and look at the <tt><nowiki>[ASCII DEC / CHAR]</nowiki></tt> box for the result. And alternative would be to use Nasal (in the [[Nasal Console]] or [[Interactive Nasal REPL|REPL]]), with a simple script like this that will "pop up" the result:
For printable/ASCII keys (e.g. any letter of the alphabet, number, or symbol found on a keyboard), this is simply the ASCII value of the key.  
 
=== Using the property browser ===
{{tip|You may want to press {{key press|p}} to pause the simulation first in order to not mess up something.}}
 
One of the easier ways to find out the key codes is to open up the [[property browser]] by pressing {{key press|/}} or {{key press|Shift|7}} and go to
 
* <code>/devices/status/keyboard/event/</code>
** <code>key= <nowiki>'A'</nowiki> (int)</code> – The key code of the currently or last pressed key
** <code>modifier/</code> – Key modifiers of the currently or last pressed key
*** <code>alt= <nowiki>'false'</nowiki> (bool)</code>
*** <code>ctrl= <nowiki>'false'</nowiki> (bool)</code>
*** <code>hyper= <nowiki>'false'</nowiki> (bool)</code>
*** <code>meta= <nowiki>'false'</nowiki> (bool)</code>
*** <code>shift= <nowiki>'true'</nowiki> (bool)</code>
*** <code>super= <nowiki>'false'</nowiki> (bool)</code>
** <code>pressed= <nowiki>'true'</nowiki> (bool)</code> – True if the key is currently pressed down
 
The above will be the values if you hold down {{key press|Shift|A}}.
 
=== Using a nasal script ===
An alternative would be to use Nasal (in the [[Nasal Console]] or [[Interactive Nasal REPL|REPL]]), with a simple script like this that will "pop up" the result:
 
<syntaxhighlight lang="nasal">
<syntaxhighlight lang="nasal">
gui.popupTip(`a`); # replace with the key you want to test
gui.popupTip(`a`); # replace with the key you want to test
</syntaxhighlight>
</syntaxhighlight>
No matter what method you use, for "a" (lowercase), you should get 97; "A" (uppercase) is 67; "0" would be 48.
No matter what method you use, for "a" (lowercase), you should get 97; "A" (uppercase) is 67; "0" would be 48.


For non-printable characters, the simplest option is to look for the specific key (or control key) in keyboard.xml. For example, {{key press|Ctrl|N}} is found on line 154, which reads:
=== By looking in keyboard.xml ===
For non-printable characters, the simplest option is to look for the specific key (or control key) in keyboard.xml. For example, {{key press|Ctrl|N}} is found on line 154 in keyboard.xml, which reads:
 
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
<key n="14">
<key n="14">
Line 95: Line 120:
</key>
</key>
</syntaxhighlight>
</syntaxhighlight>
Thus the key is found at index 14.


Thus the key code is 14 (as well as the index of the key binding).
=== By enabling special debugging output ===
If the key isn't listed in keyboard.xml, the last option is to enable some helpful output to see what the correct keycode is. Uncomment {{git file|gitorious|fg/fgdata|master|keyboard.xml|39|pre=line #34 of <nowiki> </nowiki> }} and run with the <tt>--console</tt> option, if on windows, and look at the console to see each keycode for each key. Make sure you can see the output as you press keys, or you won't know which is which! When I press and release {{key press|a}}, I get this output:
If the key isn't listed in keyboard.xml, the last option is to enable some helpful output to see what the correct keycode is. Uncomment {{git file|gitorious|fg/fgdata|master|keyboard.xml|39|pre=line #34 of <nowiki> </nowiki> }} and run with the <tt>--console</tt> option, if on windows, and look at the console to see each keycode for each key. Make sure you can see the output as you press keys, or you won't know which is which! When I press and release {{key press|a}}, I get this output:
<syntaxhighlight lang="nasal">
<syntaxhighlight lang="nasal">
{ key: 97, modifier: { meta: 0, shift: 0, alt: 0, super: 0, ctrl: 0, hyper: 0 }, pressed: 1 }
{ key: 97, modifier: { meta: 0, shift: 0, alt: 0, super: 0, ctrl: 0, hyper: 0 }, pressed: 1 }
{ key: 97, modifier: { meta: 0, shift: 0, alt: 0, super: 0, ctrl: 0, hyper: 0 }, pressed: 0 }
{ key: 97, modifier: { meta: 0, shift: 0, alt: 0, super: 0, ctrl: 0, hyper: 0 }, pressed: 0 }
</syntaxhighlight>
</syntaxhighlight>
This shows that key 97 was pressed (without any modifiers) and then released. This view can also help with combining modifiers, like mod-meta above.
This shows that key 97 was pressed (without any modifiers) and then released. This view can also help with combining modifiers, like mod-meta above.


Navigation menu