***************************************************************** ***************************************************************** ******************** LINUX KEYBOARD TUTORIAL ******************** ***************************************************************** ***************************************************************** Keyboard, keymap, layout all refer to the same thing. Layout is kind of the formal one used by all platforms. Linux keymaps are defined under the X11 system. There are three files involved in making a keymap, at least in the three distros I tested (Slacko Puppy and two flavors of Ubantu: Kubuntu and Mint Rebecca). In Slacko Puppy, the X11 directory is in its classic location: /etc/X11 In Kubuntu and Mint Rebecca, it is at: /usr/share/X11 We usually define our keymaps inside layout files named for countries: us, af etc. We can also place them inside special purpose layout files named appropriately, for instance, 'romanized' meaning 'all romanized keymaps go inside here'. So, a layout file can contain more than one keymap definition. The first tutorial is how to make a special purpose keymap inside its own layout file, may be for your own personal use and testing. The second one tells how to add a keymap to an existing layout file. But first, on editing files... ******************************************* ********** EDITING SYSTEMS FILES ********** ******************************************* Except in Puppy, you need special permission to edit system files. ***** Slacko Puppy ***** (Perhaps it is possible to have the pattern of file system follow that of the distro a particular branch of Puppy feeds out of) The layout files in my Slacko Puppy are in /etc/X11/xkb/symbols/pc/ ***** Ubuntu ***** Layout file location: /usr/share/X11/xkb/symbols/ KUBUNTU In Kubuntu, you cannot edit files in situ. At least, I couldn't. I first created the keymap on the desktop and copied the two required files in the 'rules' folder to the desktop as well. Then I copied them to their respective locations using the cp copy command inside the terminal window. In order to get the ability to copy them, I changed my credentials to that of root by using the command 'sudo su-' and supplying the password. It will stay blank, with no clue if it is accepting your input — the Linux poker face. The terminal commands I used in Kubuntu to copy a file edited on Desktop to location: sudo su- [type your password] cp /home/[user-name]/Desktop/[layout-file-name] /usr/share/X11/xkb/symbols/[layout-file-name] For the other two files that we will discuss later, the file path changes replacing 'symbols' to 'rules'. LINUX MINT What a relief! Open the directory (folder) of the file you want to edit, right-click on a blank area and select 'Open as Root'. It even shows the dots for password! The folder will open in a new window with a red bar at top. Just create or edit the file right there. Caveat: Before editing a file, I'd open it from a regular folder without root privileges. This way, you have the original in read-only mode to get back to, in case Mint messes up your typing by suddenly whisking away the cursor to some other place. This is a bug in Mint on my computer. Even so, Mint is the best one to test the changes because it displays an error box on start up or when you try to set up a layout variant using keyboard settings. The other two would stay silent with errors. **************************************************** **************************************************** ********** 1. MAKING A STAND-ALONE LAYOUT ********** **************************************************** **************************************************** Below is the contents of the standalone layout map I tested. (Look toward the bottom past two double lines for the number 2 tutorial on how to add a keymap to an existing layout file). I named this layout file 'romanized' and placed it as follows: FILE LOCATION Puppy: in X11/xkb/symbols/pc/romanized Ubuntu (Kubuntu & Mint): X11/xkb/symbols/romanized Read explanations below the ending asterisk lines. (Skip the // comment lines to get to the meat that starts with the word 'default'). ****************************** BEGIN SAMPLE KEYMAP ****************************** // SINGHALA - DUAL-SCRIPT (ROMANIZED SINGHALA) // =========================================== // // This keymap is made for fast typing romanized Singhala. Only three keys // produce letters different from those stamped on key caps: // Q -> Edh (ð), W -> Ash (æ), F -> Thorn (þ). // // It provides the accent marks necessary to type (Latin) PTS Pali as well: // Dead keys: // AltGr-1 = bar for long vowels, AltGr-2 = dot below (for muurdhaja) and // AltGr-3 = above dot (for Anusvara m) // // And some handy characters... // AltGr-5 = UB0 = degree sign; AltGr-minus = em-dash; // AltGr-< and AltGr-> = UAB and UBB = left and right double angle quotes. // // This keyboard can be used to type Singhala, Sanskrit and Pali to yield text // in the traditional Singhala script when used in conjunction with a Singhala // smartfont. // // The font below can be used to type in the traditional Singhala script using // the phoneme chart (Singhala: 'hodiya' Sanskrit: 'soDI'): // smartfont: http://smartfonts.net/singhala/anura.ttf // hodiya: http://ahangama.com/hodiya/hodiya3.htm // // Dedication: // Rev. Fr. A. M. Gunasekara, Rev. Fr. Theodore G. Perera // Ven. Gnanaponika, Ven. Mettavihari // // Maintainer: // JC Ahangama - sing@ahangama.com // default partial alphanumeric_keys modifier_keys xkb_symbols "singhala" { name[Group1]= "Singhala"; include "us(basic)" include "level3(alt_switch)" // // UNSHIFTED, SHIFT, ALT // -------------------------------------------- // key { [ grave, asciitilde, VoidSymbol ] }; key { [ one, exclam, dead_macron ] }; key { [ two, at, dead_belowdot ] }; key { [ three, numbersign, dead_abovedot ] }; key { [ four, dollar, currency ] }; key { [ five, percent, UB0 ] }; key { [ six, asciicircum, onequarter ] }; key { [ seven, ampersand, onehalf ] }; key { [ eight, asterisk, threequarters ] }; key { [ nine, parenleft, VoidSymbol ] }; key { [ zero, parenright, VoidSymbol ] }; key { [ minus, underscore, U2014 ] }; key { [ equal, plus, VoidSymbol ] }; key { [ eth, ETH, q ] }; key { [ ae, acute, w ] }; key { [ e, eacute, ediaeresis ] }; key { [ r, ucircumflex, VoidSymbol ] }; key { [ t, VoidSymbol, VoidSymbol ] }; key { [ y, VoidSymbol, VoidSymbol ] }; key { [ u, uacute, udiaeresis ] }; key { [ i, iacute, idiaeresis ] }; key { [ o, oacute, odiaeresis ] }; key { [ p, VoidSymbol, VoidSymbol ] }; key { [ bracketleft, braceleft, VoidSymbol ] }; key { [ bracketright, braceright, VoidSymbol ] }; key { [ a, aacute, adiaeresis ] }; key { [ s, VoidSymbol, VoidSymbol ] }; key { [ d, D, VoidSymbol ] }; key { [ thorn, f, VoidSymbol ] }; key { [ g, G, VoidSymbol ] }; key { [ h, VoidSymbol, VoidSymbol ] }; key { [ j, ccedilla, VoidSymbol ] }; key { [ k, VoidSymbol, VoidSymbol ] }; key { [ l, L, ocircumflex ] }; key { [ semicolon, colon, VoidSymbol ] }; key { [ apostrophe, quotedbl, VoidSymbol ] }; key { [ z, VoidSymbol, VoidSymbol ] }; key { [ x, VoidSymbol, VoidSymbol ] }; key { [ c, ccedilla, VoidSymbol ] }; key { [ v, VoidSymbol, VoidSymbol ] }; key { [ b, B, VoidSymbol ] }; key { [ n, N, ntilde ] }; key { [ m, VoidSymbol, VoidSymbol ] }; key { [ comma, less, UAB ] }; key { [ period, greater, UBB ] }; key { [ slash, question, U200C ] }; key { [ backslash, bar, VoidSymbol ] }; key { [ space, UA0, VoidSymbol ] }; }; ******************************* END SAMPLE KEYMAP ******************************* // slashes: These mean that those lines do not count in compiling the layout. Therefore, the first valid program statement is the two lines, default partial alphanumeric_keys modifier_keys xkb_symbols "singhala" { key etc. are KEYCODES representing the keys on the physical keyboard. The items inside curly brackets {} are the key values according to key press 'Level'. Looking at the keymap, the UNSHIFTED is Level 1, SHIFTED is Level 2 and Level 3 is the ALT column. KEY WORDS default: This is used only for one keymap in a layout file, and is usually the first one in the file. If there are secondary keymaps or variants in this layout file, they omit this word from this line. partial: There may be other keys that do things not defined here modifier_keys: Shifted keys exist xkb_symbols: Name of this particular keymap name[Group1]: This is the name of the variant you see when setting up the keyboard include: Include a keymap from another layout file. include "us(basic)": Says that that the variant 'basic' inside the 'us' layout file shines through keys that are not explicitly defined on this keymap. My keymap defines every key position that 'us(basic)' defines. Therefore, this programming statement is redundant in my case. include "level3(alt_switch)": Tells to enable key selection by depressing either Alt key including AltGr (alternate graphic) key as stamped on European keyboards. This definition is in the 'level3' layout file. There is also a "level3(ralt_switch)" with an 'r' telling to use only the AltGr key on the right for this purpose like in Windows systems. DEFINING KEY NAMES As long as they are ASCII keys, you can simply type the actual key instead of the English names. Please see the 'us' layout file. It has 1, 2 in place of 'one', 'two' I used here. Notice that I have UAB, U200C etc. They came from http://www.unicode.org/charts/. The short ones are from the Basic Latin (ASCII) code block. These single byte codes need not have leading zeros. I think the most stable keymap would be defined using the Unicode codes, though the chance of you making mistakes is high. Remember to keep the 'U' capital. It means that it is a character listed in the Unicode character database. VoidSymbol: Says to ignore this key press. I have seen 'NoSymbol' used too. That did not come out as too reliable to me. ******************************************************* ********** EDITING base.xml / evdev.xml FILE ********** ******************************************************* FILE LOCATION Puppy Linux: /etc/X11/xkb/rules/base.xml Ubuntu: /usr/share/X11/xkb/rules/evdev.xml Open the file and search for the string ''. That is the closing tag of the list of layouts. We want to register our new layout file as the last layout file of the list. I added the following just above the line like here: ************* BEGIN LAYOUT DEFINITION IN base.xml or evdev.xml File ************* romanized Singhala Singhala Dual-script sin ************** END LAYOUT DEFINITION IN base.xml or evdev.xml File ************** (The last line is just for reference. Do not repeat the tag) TAG ENCLOSURES romanized: States the name of the layout file. Singhala: I did not find any relation elsewhere to this Singhala Dual-script: Name of variant found when setting up the keyboard. sin: The registered name of a human language taken from www-01.sil.org/iso639-3/codes.asp. This has no programming consequence. It might as well be 'eng'. It has a dubious use in the future. A better way to determine the language of a body of text is to use heuristic pattern discovery such as comparing frequencies of letters and finding the existence of specific words. : The ending '/>' says that it is an empty tag. That is, there are no variants to this layout. ******************************************************* ********** EDITING base.lst / evdev.lst FILE ********** ******************************************************* FILE LOCATION Puppy Linux: /etc/X11/xkb/rules/base.lst Ubuntu: /usr/share/X11/xkb/rules/evdev.lst This file has four sections as follows: ! model: Physical keyboards ! layout: Name of layout file and its defaut keymap's 'name[Group1]' value ! variant: 'xkb_symbols' name of a variant, the name of the layout file and 'name[Group1]' item. All three relating to a single layout file ! option: How various other keyboard actions are done such as switching between keymap layouts / variants. My sample would be entered as the last item under '! layouts' section because it is a keymap in a file by itself: ********** sample entry in base.lst / evdev.lst file ********** romanized Singhala REBOOT OR RESTART X11 and test. If all is well, you'll be able to set your keyboard to switch between keymaps your favorite way. I selected Ctrl-Shift. ================================================================================= ================================================================================= *********************************************************************** *********************************************************************** ********** 2. HOW TO ADD A KEYMAP TO AN EXISTING LAYOUT FILE ********** *********************************************************************** *********************************************************************** ************************************* ********** MAKE THE KEYMAP ********** ************************************* Make the keymap as above in tutorial 1, but delete the keyword 'default' from the first program line. In my case, now it would be like this: partial alphanumeric_keys modifier_keys xkb_symbols "singhala" { Actually, I made slight changes to the top lines to come out like this: ********** sample top entries of a new keymap added to a layout file ********** partial alphanumeric_keys modifier_keys xkb_symbols "singhala-DS" { name[Group1]= "Singhala Dual-script"; include "us(basic)" include "level3(alt_switch)" ****************************************************** ********** COPY KEYMAP INTO THE LAYOUT FILE ********** ****************************************************** Copy that keymap to the layout file you want to associate it with. I added mine as the last variant of 'lk' country layout file as it is for romanized form of Singhala, the native language there. /usr/share/X11/xkb/symbols/lk **************************************************** ********** EDIT base.xml / evdev.xml FILE ********** **************************************************** Register the layout variant by adding it to, /etc/X11/xkb/rules/base.xml in Puppy and /usr/share/X11/xkb/rules/evdev.xml in Ubuntu Mine was done this way: Opened the XML file. Searched for the name of the layout file '>lk<'. Then searched for the tag, ''. Pasted the block given below just above that tag. (That tag is shown here just to show you where it went to. Do not leave two lines with same tag. ********** BEGIN BLOCK ADDED TO base.xml / evdev.xml FILE ********** singhala-DS Singhala Singhala Dual-script sin *********** END BLOCK ADDED TO base.xml / evdev.xml FILE *********** **************************************************** ********** EDIT base.lst / evdev.lst FILE ********** **************************************************** FILE LOCATION Puppy: /etc/X11/xkb/rules/base.lst Ubuntu: /usr/share/X11/xkb/rules/evdev.lst Added the following line next to those listed variants for the country layout file: Searched for '! variant'. Then searched for 'lk:' in the second column. Then added the following line below them: ********** sample entry in the base.lst / evdev.lst file ********** singhala-DS lk: Singhala Dual-script *************************************************** ********** RESTART AND HOPE FOR THE BEST ********** *************************************************** REBOOT or RESTART X11 and test. Now set your keyboard to switch between keymaps your favorite way.