Jump to: navigation, search

Howto:Reassign keyboard bindings

929 bytes added, 03:29, 25 December 2014
Finding keycodes: + Subsection headings; +Using the property browser
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.  === 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 [http:[property browser]] by pressing {{key press|/}} or {{key press|Shift|7}} and go to * <code>/home.paulschou.netdevices/toolsstatus/xlatekeyboard/event/ xlate] is a simple tool that can convert from a letter to appropriate number: enter the letter in <tt/code>** <code>key= <nowiki>[TEXT]'A'</nowiki>(int)</ttcode>, click convert, and look at – The key code of the currently or last pressed key** <code>modifier/</code> – Key modifiers of the currently or last pressed key*** <ttcode>alt= <nowiki>[ASCII DEC 'false'</ CHAR]nowiki> (bool)</code>*** <code>ctrl= <nowiki>'false'</ttnowiki> box for (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 resultkey is currently pressed down The above will be the values if you hold down {{key press|Shift|A}}. And  === 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">
gui.popupTip(`a`); # replace with the key you want to test
No matter what method you use, for "a" (lowercase), you should get 97; "A" (uppercase) is 67; "0" would be 48.
=== 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 154in keyboard.xml, which reads: 
<syntaxhighlight lang="xml">
<key n="14">
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:
<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: 0 }
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