Web Analytics
Privacy Policy Cookie Policy Terms and Conditions The Linux Thai HOWTO: Thai Input and Output Next Previous Contents

2. Thai Input and Output

2.1 Linux console

Thai characters do not display properly in Linux console. If you mainly use X window, you may pass this section.

Thai fonts

You can obtain Linux Thai console fonts which created by Mr. Phaisarn Techajaruwong from ZzzThai ftp site

For example, there is a font name "phaisarn.psf". Put it in /usr/lib/kbd/consolefonts/ directory. Then, you can load the new font from Linux console by command

%setfont phaisarn.psf

Keyboard layout

You can set keyboard behavior as you like by using loadkeys command. Usually, you use loadkeys to load the file located in /usr/lib/kbd/keytables. You can create a US/Thai keyboard-map file and save it in this directory. Here is a sample.

keycode   0 =
keycode   1 = Escape           Escape          
        alt     keycode   1 = Meta_Escape     
keycode   2 = +one              exclam          +0x0e5          plus         
        alt     keycode   2 = Meta_one        
        alt shift keycode 2 = Meta_exclam
keycode   3 = +two              at              +slash          0x0f1              
        control keycode   3 = nul        
        control shift keycode 3 = nul     
        alt     keycode   3 = Meta_two        
        alt shift keycode 3 = Meta_at
keycode   4 = +three            numbersign      +underscore     0x0f2
        control keycode   4 = Escape          
        alt     keycode   4 = Meta_three      
        alt shift keycode 4 = Meta_numbersign
keycode   5 = +four             dollar          +0x0c0          0x0f3
        control keycode   5 = Control_backslash
        alt     keycode   5 = Meta_four      
        alt shift keycode 5 = Meta_dollar 
keycode   6 = +five             percent         +0x0b6          0x0f4
        control keycode   6 = Control_bracketright
        alt     keycode   6 = Meta_five  
        alt shift keycode 6 = Meta_percent     
keycode   7 = +six              asciicircum     +0x0d8          0x0d9
        control keycode   7 = Control_asciicircum
        alt     keycode   7 = Meta_six    
        alt shift keycode 7 = Meta_asciicircum    
keycode   8 = +seven            ampersand       +0x0d6          0x0df
        control keycode   8 = Control_underscore
        alt     keycode   8 = Meta_seven      
keycode   9 = +eight            asterisk        +0x0a4          0x0f5
        control keycode   9 = Delete          
        alt     keycode   9 = Meta_eight      
keycode  10 = +nine             parenleft       +0x0b5          0x0d6
        alt     keycode  10 = Meta_nine       
keycode  11 = +zero             parenright      +0x0a8          0x0f7
        alt     keycode  11 = Meta_zero       
keycode  12 = +minus            underscore      +0x0a2          0x0f8
        control keycode  12 = Control_underscore
        control shift keycode 12 = Control_underscore
        alt     keycode  12 = Meta_minus      
keycode  13 = +equal            plus            +0x0aa          0x0f9
        alt     keycode  13 = Meta_equal      
keycode  14 = Delete           Delete           Delete          Delete
        alt     keycode  14 = Meta_Delete     
keycode  15 = Tab              Tab              Tab             Tab
        alt     keycode  15 = Meta_Tab        
keycode  16 = +q        Q       +0x0e6          0x0f0  
keycode  17 = +w        W       +0x0e4          quotedbl
keycode  18 = +e        E       +0x0d3          0x0ae              
keycode  19 = +r        R       +0x0be          0x0b1
keycode  20 = +t        T       +0x0d0          0x0b8
keycode  21 = +y        Y       +0x0d1          0x0ed
keycode  22 = +u        U       +0x0d5          0x0ea
keycode  23 = +i        I       +0x0c3          0x0b3
keycode  24 = +o        O       +0x0b9          0x0cf
keycode  25 = +p        P       +0x0c2          0x0ad
keycode  26 = +bracketleft      braceleft       +0x0ba          0x0b0
        control keycode  26 = Escape          
        alt     keycode  26 = Meta_bracketleft
        alt shift keycode 26 = Meta_braceleft
keycode  27 = +bracketright     braceright      +0x0c5          comma
        control keycode  27 = Control_bracketright
        alt     keycode  27 = Meta_bracketright
        alt shift keycode 27 = Meta_braceright
keycode  28 = Return            Return          Return          Return
        alt     keycode  28 = 0x080d          
keycode  29 = Control           Control         Control         Control
keycode  30 = +a        A       +0x0bf          0x0c4
keycode  31 = +s        S       +0x0cb          0x0a6
keycode  32 = +d        D       +0x0a1          0x0af
keycode  33 = +f        F       +0x0b4          0x0e2
keycode  34 = +g        G       +0x0e0          0x0ac
keycode  35 = +h        H       +0x0e9          0x0e7
keycode  36 = +j        J       +0x0e8          0x0eb
keycode  37 = +k        K       +0x0d2          0x0c9
keycode  38 = +l        L       +0x0ca          0x0c8
keycode  39 = +semicolon        colon           +0x0c7          0x0ab
        alt     keycode  39 = Meta_semicolon  
keycode  40 = +apostrophe       quotedbl        +0x0a7          period
        control keycode  40 = Control_g       
        alt     keycode  40 = Meta_apostrophe 
keycode  41 = +grave            asciitilde      +minus          percent
        control keycode  41 = nul             
        alt     keycode  41 = Meta_grave      
keycode  42 = Shift            Shift            Shift           Shift
keycode  43 = +backslash        bar             +0x0a3          0x0a5
        control keycode  43 = Control_backslash
        alt     keycode  43 = Meta_backslash  
        alt shift keycode 43 = Meta_bar
keycode  44 = +z        Z       +0x0bc          parenleft              
keycode  45 = +x        X       +0x0bb          parenright              
keycode  46 = +c        C       +0x0e1          0x0a9
keycode  47 = +v        V       +0x0cd          0x0ce
keycode  48 = +b        B       +0x0d4          0x0da
keycode  49 = +n        N       +0x0d7          0x0ec
keycode  50 = +m        M       +0x0b7          question              
keycode  51 = +comma    less    +0x0c1          0x0b2
        alt     keycode  51 = Meta_comma      
        alt shift keycode 51 = Meta_less
keycode  52 = +period           greater         +0x0e3          0x0cc
        alt     keycode  52 = Meta_period     
        alt shift keycode 52 = Meta_greater
keycode  53 = +slash            question        +0x0bd          0x0c6
        control keycode  53 = Delete          
        alt     keycode  53 = Meta_slash      
keycode  54 = Shift            Shift            Shift           Shift
keycode  55 = KP_Multiply     
keycode  56 = Alt              Alt              Alt             Alt 
keycode  57 = space            space            space           space
        control keycode  57 = nul             
        alt     keycode  57 = Meta_space      
keycode  58 = Caps_Lock        Caps_Lock        Caps_Lock       Caps_Lock
keycode  59 = F1               F11              Console_13      
        control keycode  59 = F1              
        alt     keycode  59 = Console_1       
        control alt     keycode  59 = Console_1       
keycode  60 = F2               F12              Console_14      
        control keycode  60 = F2              
        alt     keycode  60 = Console_2       
        control alt     keycode  60 = Console_2       
keycode  61 = F3               F13              Console_15      
        control keycode  61 = F3              
        alt     keycode  61 = Console_3       
        control alt     keycode  61 = Console_3       
keycode  62 = F4               F14              Console_16      
        control keycode  62 = F4              
        alt     keycode  62 = Console_4       
        control alt     keycode  62 = Console_4       
keycode  63 = F5               F15              Console_17      
        control keycode  63 = F5              
        alt     keycode  63 = Console_5       
        control alt     keycode  63 = Console_5       
keycode  64 = F6               F16              Console_18      
        control keycode  64 = F6              
        alt     keycode  64 = Console_6       
        control alt     keycode  64 = Console_6       
keycode  65 = F7               F17              Console_19      
        control keycode  65 = F7              
        alt     keycode  65 = Console_7       
        control alt     keycode  65 = Console_7       
keycode  66 = F8               F18              Console_20      
        control keycode  66 = F8              
        alt     keycode  66 = Console_8       
        control alt     keycode  66 = Console_8       
keycode  67 = F9               F19              Console_21      
        control keycode  67 = F9              
        alt     keycode  67 = Console_9       
        control alt     keycode  67 = Console_9       
keycode  68 = F10              F20              Console_22      
        control keycode  68 = F10             
        alt     keycode  68 = Console_10      
        control alt     keycode  68 = Console_10      
keycode  69 = Num_Lock        
keycode  70 = Scroll_Lock      Show_Memory      Show_Registers  
        control keycode  70 = Show_State      
        alt     keycode  70 = Scroll_Lock     
keycode  71 = KP_7            
        alt     keycode  71 = Ascii_7         
keycode  72 = KP_8            
        alt     keycode  72 = Ascii_8         
keycode  73 = KP_9            
        alt     keycode  73 = Ascii_9         
keycode  74 = KP_Subtract     
keycode  75 = KP_4            
        alt     keycode  75 = Ascii_4         
keycode  76 = KP_5            
        alt     keycode  76 = Ascii_5         
keycode  77 = KP_6            
        alt     keycode  77 = Ascii_6         
keycode  78 = KP_Add          
keycode  79 = KP_1            
        alt     keycode  79 = Ascii_1         
keycode  80 = KP_2            
        alt     keycode  80 = Ascii_2         
keycode  81 = KP_3            
        alt     keycode  81 = Ascii_3         
keycode  82 = KP_0            
        alt     keycode  82 = Ascii_0         
keycode  83 = KP_Period       
        altgr   control keycode  83 = Boot            
        control alt     keycode  83 = Boot            
keycode  84 = Last_Console    
keycode  85 =
keycode  86 = less             greater          bar             
        alt     keycode  86 = Meta_less       
keycode  87 = F11              F11              Console_23      
        control keycode  87 = F11             
        alt     keycode  87 = Console_11      
        control alt     keycode  87 = Console_11      
keycode  88 = F12              F12              Console_24      
        control keycode  88 = F12             
        alt     keycode  88 = Console_12      
        control alt     keycode  88 = Console_12      
keycode  89 =
keycode  90 =
keycode  91 =
keycode  92 =
keycode  93 =
keycode  94 =
keycode  95 =
keycode  96 = KP_Enter        
keycode  97 = Control         
keycode  98 = KP_Divide       
keycode  99 = Control_backslash
        control keycode  99 = Control_backslash
        alt     keycode  99 = Control_backslash
keycode 100 = AltGr_Lock           
keycode 101 = Break           
keycode 102 = Find            
keycode 103 = Up              
keycode 104 = Prior           
        shift   keycode 104 = Scroll_Backward 
keycode 105 = Left            
        alt     keycode 105 = Decr_Console
keycode 106 = Right
        alt     keycode 106 = Incr_Console
keycode 107 = Select          
keycode 108 = Down            
keycode 109 = Next            
        shift   keycode 109 = Scroll_Forward  
keycode 110 = Insert          
keycode 111 = Remove          
        altgr   control keycode 111 = Boot            
        control alt     keycode 111 = Boot            
keycode 112 =
keycode 113 =
keycode 114 =
keycode 115 =
keycode 116 =
keycode 117 =
keycode 118 =
keycode 119 =
keycode 120 =
keycode 121 =
keycode 122 =
keycode 123 =
keycode 124 =
keycode 125 =
keycode 126 =
keycode 127 =
string F1 = "\033[[A"
string F2 = "\033[[B"
string F3 = "\033[[C"
string F4 = "\033[[D"
string F5 = "\033[[E"
string F6 = "\033[17~"
string F7 = "\033[18~"
string F8 = "\033[19~"
string F9 = "\033[20~"
string F10 = "\033[21~"
string F11 = "\033[23~"
string F12 = "\033[24~"
string F13 = "\033[25~"
string F14 = "\033[26~"
string F15 = "\033[28~"
string F16 = "\033[29~"
string F17 = "\033[31~"
string F18 = "\033[32~"
string F19 = "\033[33~"
string F20 = "\033[34~"
string Find = "\033[1~"
string Insert = "\033[2~"
string Remove = "\033[3~"
string Select = "\033[4~"
string Prior = "\033[5~"
string Next = "\033[6~"
string F21 = ""
string F22 = ""
string F23 = ""
string F24 = ""
string F25 = ""
string F26 = ""

Suppose you save this file as thai.map. From Linux console, use command loadkeys to load thai.map.

%loadkeys thai.map
You can switch to Thai keyboard by pressing the right Alt key. If you want to switch the keyboard back, press the right Alt key again.

2.2 X Window system

Thai fonts

You can obtain Thai fonts in bdf format or pcf format from internet. You can also use scalable fonts such as Type1 or TrueType fonts. But I will not describe about these.

Installing Thai fonts

You must log in as root. Let's put Thai fonts in /usr/X11R6/lib/X11/fonts/misc/, this is a default font path. Change directory to /usr/X11R6/lib/X11/fonts/misc/ and run command

%mkfontdir
%xset fp rehash
If you put Thai fonts in different directory, you must use xset to add the new font path. Please see man-page for further information. You can check the new fonts by running command xlsfonts and see whether there are Thai fonts or not. If you can not see any Thai fonts from this command, you may need to restart X window.

Thai keyboard layoutThere are two ways to map Thai keyboard on X window, using X KeyboardExtension (XKB) and using xmodmap. Please select how you map Thai keyboard. Irecommend using XKB.

XKB and Thai keyboard layout.

Beginning with XFree86 3.1.2D, you can use the new X11R6.1 XKEYBOARD extension to manage the keyboard layout. This is very helpful.

During X server configuration with xf86config you will be asked about XKB, if you want to to set Thai keyboard layout for your system, say yes. There are a list of pre-configured keymaps. Choose Standard 101-key, Thai encoding.

XF86Setup is the graphical X server configuration utility for XFree86 X server. It is easier than traditional xf86config. You can select a keyboard layout easily with this tool.

Ther are many choices of keyboard switch key to select. The default is LeftAlt+RightShift switch to Thai and LeftAlt+LeftShift switch to US. You can type Thai characters in any applications which support ISO-8859-1 character set, but don't forget to use Thai fonts with those applications too.

I found that pre-configured keymaps that came with XFree86-3.2 is not correct. You may not be able to type THO THUNG which located at " 5 key " . To fix this problem, you should add the line

    key <AE05> {     [], [   paragraph,      ocircumflex     ]       };
in the file /usr/X11R6/lib/X11/xkb/symbols/th as the example.
.................
    key <AE03> {        [], [       minus,      ograve          ]       };
    key <AE04> {        [], [      Agrave,      oacute          ]       };
    key <AE05> {     [], [   paragraph,      ocircumflex     ]       };
    key <AE06> {        [], [    Ooblique,      Ugrave          ]       };
    key <AE07> {        [], [  Odiaeresis,      ssharp          ]       };
.................
You can not type SORUSI also. Please change the line from
    key <AC08> {        [], [      Ograve,      eacute          ]       };
to
    key <AC08> {        [], [      Ograve,      Eacute          ]       };
Note that eacute is equal to MAITHO and Eacute is equal to SORUSI.

There are also XKB extension utilities such as setxkbmap, xkbcomp, etc. Please see man-page for more information. I recommend to use xkbvled. The leds will be on when you are using Thai keyboard so you can know your keyboard's status.

The following is part of XF86Config file about keyboard section. If you want to configure the keyboard by hand, change the content of /usr/X11R6/lib/X11/XF86Config as an example below. This configuration uses the default toggle key.

Section "Keyboard"
   Protocol        "Standard"
   AutoRepeat      500 5
   LeftAlt         Meta
   RightAlt        Meta
   ScrollLock      Compose
   RightCtl        Control
#  XkbDisable
   XkbKeycodes     "xfree86"
   XkbTypes        "default"
   XkbCompat       "default"
   XkbSymbols      "us(pc101)"
   XkbGeometry     "pc"
   XkbRules        "xfree86"
   XkbModel        "pc101"
   XkbLayout       "th"
EndSection

If you use XKB extension, Thai keyboard mapping with xmodmap may not work. See XF86Config man-page for mor information.

Thai keyboard layout with xmodmap

You can use the utility xmodmap to map Thai keyboard. Normally xmodmap is used to load a keyboard configured file. For most Linux distributions, when you start X window with startx, X server will find .Xmodmap in /usr/X11R6/lib/X11/xinit/ first. If .Xmodmap does not exist, X server will find .Xmodmap in your home directory. Please see the content of /usr/X11R6/lib/X11/xinit/xinitrc.

The following is the sample of .Xmodmap for Thai Kedmanee keyboard layout.

!
! Linux/XFree86 Thai Kedmanee layout (based on US keyboard)
! Use ScrollLock to switch to Thai keyboard.
! This file will work with XFree86 only.
!

keycode 0x09 =  Escape
keycode 0x43 =  F1
keycode 0x44 =  F2
keycode 0x45 =  F3
keycode 0x46 =  F4
keycode 0x47 =  F5
keycode 0x48 =  F6
keycode 0x49 =  F7
keycode 0x4A =  F8
keycode 0x4B =  F9
keycode 0x4C =  F10
keycode 0x5F =  F11
keycode 0x60 =  F12
keycode 0x6F =  Print
keycode 0x4E =  Mode_switch     XF86ModeLock
keycode 0x6E =  Pause
keycode 0x31 =  grave           asciitilde      minus           percent
keycode 0x0A =  1               exclam          0x0e5           plus
keycode 0x0B =  2               at              slash           0x0f1
keycode 0x0C =  3               numbersign      underscore      0x0f2
keycode 0x0D =  4               dollar          0x0c0           0x0f3
keycode 0x0E =  5               percent         0x0b6           0x0f4
keycode 0x0F =  6               asciicircum     0x0d8           0x0d9
keycode 0x10 =  7               ampersand       0x0d6           0x0df
keycode 0x11 =  8               asterisk        0x0a4           0x0f5
keycode 0x12 =  9               parenleft       0x0b5           0x0f6
keycode 0x13 =  0               parenright      0x0a8           0x0f7
keycode 0x14 =  minus           underscore      0x0a2           0x0f8
keycode 0x15 =  equal           plus            0x0aa           0x0f9
keycode 0x33 =  backslash       bar             0x0a3           0x0a5
keycode 0x16 =  BackSpace
keycode 0x6A =  Insert
keycode 0x61 =  Home
keycode 0x63 =  Prior
keycode 0x4D =  Num_Lock
keycode 0x70 =  KP_Divide
keycode 0x3F =  KP_Multiply
keycode 0x52 =  KP_Subtract
keycode 0x17 =  Tab
keycode 0x18 =  q               Q               0x0e6           0x0f0
keycode 0x19 =  w               W               0x0e4           quotedbl
keycode 0x1A =  e               E               0x0d3           0x0ae
keycode 0x1B =  r               R               0x0be           0x0b1
keycode 0x1C =  t               T               0x0d0           0x0b8
keycode 0x1D =  y               Y               0x0d1           0x0ed
keycode 0x1E =  u               U               0x0d5           0x0ea
keycode 0x1F =  i               I               0x0c3           0x0b3
keycode 0x20 =  o               O               0x0b9           0x0cf
keycode 0x21 =  p               P               0x0c2           0x0ad
keycode 0x22 =  bracketleft     braceleft       0x0ba           0x0b0
keycode 0x23 =  bracketright    braceright      0x0c5           comma
keycode 0x24 =  Return
keycode 0x6B =  Delete
keycode 0x67 =  End
keycode 0x69 =  Next
keycode 0x4F =  KP_7
keycode 0x50 =  KP_8
keycode 0x51 =  KP_9
keycode 0x56 =  KP_Add
keycode 0x42 =  Caps_Lock
keycode 0x26 =  a               A               0x0bf           0x0c4
keycode 0x27 =  s               S               0x0cb           0c0a6
keycode 0x28 =  d               D               0x0a1           0x0af
keycode 0x29 =  f               F               0x0b4           0x0e2
keycode 0x2A =  g               G               0x0e0           0x0ac
keycode 0x2B =  h               H               0x0e9           0x0e7
keycode 0x2C =  j               J               0x0e8           0x0eb
keycode 0x2D =  k               K               0x0d2           0x0c9
keycode 0x2E =  l               L               0x0ca           0x0c8
keycode 0x2F =  semicolon       colon           0x0c7           0x0ab
keycode 0x30 =  apostrophe      quotedbl        0x0a7           period
keycode 0x53 =  KP_4
keycode 0x54 =  KP_5
keycode 0x55 =  KP_6
keycode 0x32 =  Shift_L
keycode 0x34 =  z               Z               0x0bc           parenleft
keycode 0x35 =  x               X               0x0bb           parenright
keycode 0x36 =  c               C               0x0e1           0x0a9
keycode 0x37 =  v               V               0x0cd           0x0ce
keycode 0x38 =  b               B               0x0d4           0x0da
keycode 0x39 =  n               N               0x0d7           0x0ec
keycode 0x3A =  m               M               0x0b7           question
keycode 0x3B =  comma           less            0x0c1           0x0b2
keycode 0x3C =  period          greater         0x0e3           0x0cc
keycode 0x3D =  slash           question        0x0bd           0x0c6
keycode 0x3E =  Shift_R
keycode 0x62 =  Up
keycode 0x57 =  KP_1
keycode 0x58 =  KP_2
keycode 0x59 =  KP_3
keycode 0x6C =  KP_Enter
keycode 0x25 =  Control_L
keycode 0x40 =  Alt_L           Meta_L
keycode 0x41 =  space
keycode 0x71 =  Alt_R           Meta_R
keycode 0x6D =  Control_R
keycode 0x64 =  Left
keycode 0x68 =  Down
keycode 0x66 =  Right
keycode 0x5A =  KP_0
keycode 0x5B =  KP_Decimal

clear Shift
clear Lock
clear Control
clear Mod1
clear Mod2
clear Mod3
clear Mod4
clear Mod5

add    Shift   = Shift_L Shift_R
add    Lock    = Caps_Lock
add    Control = Control_L Control_R
add    Mod1    = Alt_L Alt_R
add    Mod2    = Mode_switch
Just put .Xmodmap in your home directory will be OK. When you start X window, X server will load this file.

You can also load .Xmodmap from command line.

%xmodmap ~/.Xmodmap

In above .Xmodmap file, US/Thai switch key is assigned to keycode 0x4E (78), Scroll Lock key, with the statement


keycode 0x4E =  Mode_switch     XF86ModeLock

XF86ModeLock is the special keysym for XFree86 X server. If you don't add this keysym, you have to hold the scroll lock key while you are typing Thai characters. Note that if you use commercial X server, some keycodes are different. You may have to map keyboard by yourself. See man-pages of X and xev for further information.

Note: If you are using XFree86 version 3.1.2D or later, you need to add the line XkbDisable in keyboard section of XF86Config file. You may config the keyboard section like the following sample.

Section "Keyboard"
   Protocol        "Standard"
   AutoRepeat      500 5
   LeftAlt         Meta
   RightAlt        ModeShift
   ScrollLock      ModeLock
   RightCtl        Compose
   XkbDisable
EndSection


Next Previous Contents