Remapping keyboard
(→Known Remap Bugs) |
(→Known Remap Bugs) |
||
Line 220: | Line 220: | ||
As of this writing, FreOffice did not register a tab mapped to either fn+spacebar or shift+spacebar. Other keys for Tab worked fine. | As of this writing, FreOffice did not register a tab mapped to either fn+spacebar or shift+spacebar. Other keys for Tab worked fine. | ||
+ | |||
+ | Also, making the arrow keys have four buttons mapped to them instead of just two tends to cause problems with shift+arrow-key to highlight text. | ||
J-k and Z-X are two pairs of keys for which pressing shift+fn+(key) causes the typing of both that key's fourth-level mapped character, and the pair key's fourth level character. So, with default mappings, shift+fn+j types ")&", as does "shift-fn-k". So mapping those characters to separate keys at the fourth level is typically counter productive, though it could be useful for writing programs, scripts, or just mathematical expressions if you map [ to one and ] to the next one, or {}, (), or <>. | J-k and Z-X are two pairs of keys for which pressing shift+fn+(key) causes the typing of both that key's fourth-level mapped character, and the pair key's fourth level character. So, with default mappings, shift+fn+j types ")&", as does "shift-fn-k". So mapping those characters to separate keys at the fourth level is typically counter productive, though it could be useful for writing programs, scripts, or just mathematical expressions if you map [ to one and ] to the next one, or {}, (), or <>. |
Revision as of 01:46, 10 February 2011
If you are not satisfied with your hardware keyboard layout, with root access (through rootsh or ssh) you can modify that as follows.
Contents |
Permanent remap
You need to edit this file on your N900: /usr/share/X11/xkb/symbols/nokia_vndr/rx-51
This can be done by using vi, which is ran from command line with the command "vi [file path and name of file to be opened]". (Instructions on how to use vi - it's not intuitive - can be found online easily.) To be able to actually edit the rx-51 file, you have to be root already. You cannot become root from within vi. Any other text or source code editor works too, such as leafpad.
You should however make a copy first in case something goes wrong, but do not place the copy in the nokia_vndr
folder or it will stop your phone from booting.
After modifying the rx-51 file, type `setxkbmap' to apply any changes for English keyboards, `setxkbmap de' for German keyboards, etc. If you see an error you should replace the rx-51 file with your backup - if you don't the device will fail to boot and you'll have to reflash it!
If you are satisfied with your new rx-51 file, do also backup that. The next firmware upgrade might restore it to the factory default.
Locales and languages can also be added with relevant keyboard stickers.
Remapping keyboard arrows
In the English variant of the N900 keyboard arrow keys have no extra symbols attached to them.
You can remap those keys to add things such as accents, umlauts or other useful symbols (e.g. `|', `<' or `>' for the X terminal).
The arrow keys are located at the end of the file. This example shows how to add dead acute, grave, tilde and circumflex accents (useful for writing in Portuguese) Press Fn+Up/Down/Left/Right to use these accents.
xkb_symbols "arrows_4btns" { key <UP> { type[Group1] = "PC_FN_LEVEL2", symbols[Group1] = [ Up, dead_circumflex ] }; key <LEFT> { type[Group1] = "PC_FN_LEVEL2", symbols[Group1] = [ Left, dead_acute ] }; key <DOWN> { type[Group1] = "PC_FN_LEVEL2", symbols[Group1] = [ Down, dead_tilde ] }; key <RGHT> { type[Group1] = "PC_FN_LEVEL2", symbols[Group1] = [ Right, dead_grave ] }; };
This example adds German umlauts:
xkb_symbols "arrows_4btns" { key <UP> { type[Group1] = "PC_FN_LEVEL2", symbols[Group1] = [ Up, udiaeresis ] }; key <LEFT> { type[Group1] = "PC_FN_LEVEL2", symbols[Group1] = [ Left, odiaeresis ] }; key <DOWN> { type[Group1] = "PC_FN_LEVEL2", symbols[Group1] = [ Down, adiaeresis ] }; key <RGHT> { type[Group1] = "PC_FN_LEVEL2", symbols[Group1] = [ Right, ssharp ] }; };
This one adds Page Up, Page Down, Home and End:
xkb_symbols "arrows_4btns" { key <UP> { type[Group1] = "PC_FN_LEVEL2", symbols[Group1] = [ Up, Page_Up ] }; key <LEFT> { type[Group1] = "PC_FN_LEVEL2", symbols[Group1] = [ Left, Home ] }; key <DOWN> { type[Group1] = "PC_FN_LEVEL2", symbols[Group1] = [ Down, Page_Down ] }; key <RGHT> { type[Group1] = "PC_FN_LEVEL2", symbols[Group1] = [ Right, End ] }; };
This one gives Escape and Tab when pressing Fn+Left/Right, and the characters '^', '~', '<' and '>' when pressing Shift+Up/Down/Left/Right
xkb_symbols "arrows_4btns" { key <UP> { type[Group1] = "FOUR_LEVEL",symbols[Group1] = [ Up, asciicircum, PageUp, PageUp ] }; key <LEFT> { type[Group1] = "FOUR_LEVEL", symbols[Group1] = [ Left, less, Escape, Escape ] }; key <DOWN> { type[Group1] = "FOUR_LEVEL", symbols[Group1] = [ Down, asciitilde, PageDown, PageDown ] }; key <RGHT> { type[Group1] = "FOUR_LEVEL", symbols[Group1] = [ Right, greater, Tab, Tab ] }; };
thp's mapping: Helpful for Python, Vim and the Shell with the occasional German (umlauts and ß) thrown in. This one adds the dead diaeresis (for Umlauts) to Shift+Fn+Up, % to Fn+Up, | to Shift+Up. Left and Right are mapped so that Shift gives <>, Fn gives [] and Shift+Fn gives {} (especially useful for programmers). It also maps Escape to Shift+Down, Tab to Fn+Down and ß to Shift+Fn+Down.
Semantic explanation: Left, Right are all kinds of bracket pairs, Shift+Fn is for German characters (up as in Umlauts, down for ß), Up has visible special characters (% and |) and Down has invisible special keys (Tab and Escape).
xkb_symbols "arrows_4btns" { key <UP> { type[Group1] = "FOUR_LEVEL", symbols[Group1] = [ Up, bar, percent, dead_diaeresis ] }; key <LEFT> { type[Group1] = "FOUR_LEVEL", symbols[Group1] = [ Left, less, bracketleft, braceleft ] }; key <DOWN> { type[Group1] = "FOUR_LEVEL", symbols[Group1] = [ Down, Escape, Tab, ssharp ] }; key <RGHT> { type[Group1] = "FOUR_LEVEL", symbols[Group1] = [ Right, greater, bracketright, braceright ] }; };
Of couse all these are just examples. You can add any other symbol you like, or you can remap any other key, not just the arrows.
If you want to know the name of a symbol, just take a look at this list of standard PC keyboard layouts as an example:
http://cgit.freedesktop.org/xkeyboard-config/tree/symbols/
An alternative approach for getting custom special characters is to edit the Special characters view.
Note: the pipe symbol is called "bar".
Example for keyboard with only two arrow keys
Non-English keyboards typically have only two keys for arrows, with Up and Down composed as Fn+Left and Fn+Right, respectively.
In this situation it may be useful to remap keys with characters carrying accents such that one of it is a dead accent, freeing other keys for special characters that you want to have on the hardware keyboard.
For example, on a German keyboard there are three keys occupied by umlauts ä, ö, and ü. The following modification changes ü into dead diaeresis, so that ä, ö, and ü are produced by pressing ü followed by a, o, and u. This way one can also put diaeresis on e, i, and y which occur in other languages.
partial alphanumeric_keys xkb_symbols "de" { include "nokia_vndr/rx-51(english_base)" include "nokia_vndr/rx-51(arrows_2btns)" name[Group1] = "German"; // 1. row key <AD06> { [ z, Z, 6, 6 ] }; // key <AB08> { [ udiaeresis, Udiaeresis, ssharp, ssharp ] }; key <AB08> { [ dead_diaeresis, asciicircum, ssharp, ssharp ] }; // 2. row key <AC08> { [ k, K, semicolon, semicolon ] }; key <AC09> { [ l, L, colon, colon ] }; //key <AB09> { [ odiaeresis, Odiaeresis, exclam, exclam ] }; key <AB09> { [ bracketleft, braceleft, exclam, exclam ] }; //key <UP> { [ adiaeresis, Adiaeresis, question, question ] }; key <UP> { [ bracketright, braceright, question, question ] }; // 3. row key <AB01> { [ y, Y, EuroSign, EuroSign ] }; key <AB03> { [ c, C, equal, equal ] }; // key <SPCE> { [ space, space, at, at ] }; key <SPCE> { [ space, asciitilde, at, at ] }; //key <LEFT> { [ period, comma, comma, comma ] }; key <LEFT> { [ period, bar, comma, comma ] }; };
In this example, brackets and braces have then be mapped on ö, ä, Ö, and Ä. Shift-ü has been used for "^". Moreover, Shift-Space has been mapped to tilde (a character that often occurs in URLs), and Shift-. has been mapped to "|". (The previous assignments are commented out by adding "//" in the beginning of a line.)
setxkbmap de
then tests and installs the new keyboard mapping. The new keymap will be used until the rx-51 file is modified again, which may happen after a firmware upgrade. So keep also a backup copy of your modified rx-51!
In the italian layout, the comma, period, up and left keys are mapped to è, ò, à and comma. In this example, we'll put the four arrow keys back and we'll change the keys to allow for all accent combinations regardless.
partial alphanumeric_keys xkb_symbols "it" { include "nokia_vndr/rx-51(english_base)" //include "nokia_vndr/rx-51(arrows_2btns)" include "nokia_vndr/rx-51(arrows_4btns)" name[Group1] = "Italian"; // 1. row //key <AB08> { [ egrave, Egrave, eacute, Eacute ] }; key <AB08> { [ egrave, dead_grave, agrave, dead_acute ] }; // 2. row key <AC06> { [ h, H, semicolon, semicolon ] }; key <AC07> { [ j, J, colon, colon ] }; key <AC08> { [ k, K, exclam, exclam ] }; key <AC09> { [ l, L, question, question ] }; //key <AB09> { [ ograve, Ograve, igrave, Igrave ] }; key <AB09> { [ period, comma, ograve, Igrave ] }; //key <UP> { [ agrave, Agrave, ugrave, Ugrave ] }; // 3. row key <AB01> { [ z, Z, EuroSign, EuroSign ] }; key <AB02> { [ x, X, parenleft, parenleft ] }; key <AB03> { [ c, C, parenright, parenright ] }; //key <LEFT> { [ period, comma, comma, comma ] }; };
With this setup, you have dead grave and acute accents on Shift-è and Fn-Shift-è, and you have à on Fn-è. Period and comma have been moved to the ò key, as ò and Shift-ò, while ò and ì are on that key, as Fn-ò and Fn-Shift-ò. There's no key for the ù character, but you can write it using the dead accents (Shift-è and then u).
Temporary remap
Keys can be also remapped temporarily by loading keymap to a file, edit that file and then reload changed file to N900 X server; like this (on an X terminal):
xkbcomp :0 vi server-0.xkb xkbcomp server-0.xkb :0
This has the advantage that if keymap get screwed out, running just setxkbmap
will fix it back to original. If this cannot be done, rebooting will fix things for sure.
For arrow key remapping the following script can be handy:
Just noticed that this makes N900 drain battery !!! (N900 was shutdown in the morning). After executing this maemo-xinput-sounds takes >90% of cpu time. Killing the process will be a temporary fix; I'll look for better solution...
#!/bin/sh set -eux # busybox mktemp is sooo strict: 6 X:s at the end is the only option... tf=`mktemp xkb-XXXXXX` trap "rm $tf.0 $tf" 0 xkbcomp :0 $tf.0 perl -pe ' sub out ($$$) { print qq( key <$_[0]> { type[Group1] = "PC_FN_LEVEL2",); print qq( symbols[Group1] = [ $_[1], $_[2] ] };); return if s/.*};//; while (<>) { last if s/.*};//; }; } s/controls=\)/controls=SlowKeys\)/; # hmm... out "UP", "Up", "Odiaeresis" if (/key\s+<UP>/); out "DOWN", "Down", "adiaeresis" if (/key\s+<DOWN>/); out "LEFT", "Left", "odiaeresis" if (/key\s+<LEFT>/); out "RGHT", "Right", "Adiaeresis" if (/key\s+<RGHT>/); ' $tf.0 > $tf xkbcomp $tf :0
This one maps Up, Down, Left and Right to Ö, ä, ö, Ä, respectively (for finnish/scandinavian users), and is easy to tune for other purposes. Copy this as xk
to home directory on N900 and execute it as sh xk
whenever (seldom) you reboot N900.
Known Remap Bugs
There are some programs that do not pick up remapped keys correctly. X-Terminal, for instance, picks up a tab that's been mapped to a shift+(key) combination as a shift+tab instead of just tab. MicroB did something similar as of this writing.
As of this writing, FreOffice did not register a tab mapped to either fn+spacebar or shift+spacebar. Other keys for Tab worked fine.
Also, making the arrow keys have four buttons mapped to them instead of just two tends to cause problems with shift+arrow-key to highlight text.
J-k and Z-X are two pairs of keys for which pressing shift+fn+(key) causes the typing of both that key's fourth-level mapped character, and the pair key's fourth level character. So, with default mappings, shift+fn+j types ")&", as does "shift-fn-k". So mapping those characters to separate keys at the fourth level is typically counter productive, though it could be useful for writing programs, scripts, or just mathematical expressions if you map [ to one and ] to the next one, or {}, (), or <>.
Alternatively, you can delete one of the fourth-row key-maps from the keys in each pair, leaving it with only three characters (make sure to delete the last comma), and then both of those buttons will simply display the one key that's left.