Plan 9: Devanagari Input with kbmap
Note: The demo uses layer 3 for better key visualization while using Devanagari.
The PS/2 interface presents two physical layers, switched on if the input scancode is one or two bytes. This second "escaped" layer is typically generated for keys like `Home' and `Ins'. Kbdfs additionally maintains eight more virtual layers that are switched on `Shift', `Ctl', `AltGr', and `Mod4' modifier key state. Not all permutations of these modifiers are represented as layers, the exhaustive list is as follows: none Key shift Shift + Key esc Escaped Key altgr AltGr + Key ctl Ctl + Key ctlesc Ctl + Escaped Key shiftesc Shift + Escaped Key shiftaltgr Shift + AltGr + Key mod4 Mod4 + Key altgrmod4 AltGr + Mod4 + Key
To use AltGr + k = क, use one of the following:
Refer to /sys/lib/kbmap/us for scan code (sc) to key mapping. Once you're satisfied with the mapping, you can generate the language file and place it in /sys/lib/kbmap/. Then you can use kbmap or kbremap (using Ctrl + space) command to change the input method on the fly.
For composing using Alt, the definitions are in /lib/keyboard.
00A3 l$ £ pound sign
Pre-requisites
- A font supporting the unicode codepoint. You need Truetype Font for composite glyphs.
- Text shaping support in libdraw.
Suggested Layout for Devanagari
Layers used: 0=none, 1=shift, 3=altgr, 7=shiftaltgr (skipping esc/ctlesc/shiftesc — those only fire for 2-byte escape scancodes, irrelevant to plain letter keys; skipping ctl/mod4 to avoid clobbering editor/WM bindings).
Consonants (dental/retroflex and unaspirated/aspirated pairs share a key):
| key | sc | 0 | 1 | 3 | 7 |
|---|---|---|---|---|---|
| k | 37 | क | ख | ||
| g | 34 | ग | घ | ||
| c | 46 | च | छ | ||
| j | 36 | ज | झ | ||
| t | 20 | त | ट | थ | ठ |
| d | 32 | द | ड | ध | ढ |
| n | 49 | न | ण | ||
| p | 25 | प | फ |
||
| b | 48 | ब | भ | ||
| m | 50 | म | |||
| y | 21 | य | |||
| r | 19 | र | |||
| l | 38 | ल | |||
| v | 47 | व | |||
| s | 31 | स | ष | श | |
| h | 35 | ह | |||
| q | 16 | ङ | |||
| x | 45 | ञ |
Vowels (0=independent, 1=matra, 3=independent marked, 7=matra marked):
| key | sc | 0 | 1 | 3 | 7 |
|---|---|---|---|---|---|
| a | 30 | अ | ा | आ | |
| i | 23 | इ | ि | ई | ी |
| u | 22 | उ | ु | ऊ | ू |
| e | 18 | ए | े | ऐ | ै |
| o | 24 | ओ | ो | औ | ौ |
Marks (spare letters):
| key | sc | 0 | 1 | 3 | 7 |
|---|---|---|---|---|---|
| z | 44 | ं | ँ | ः | ॐ |
| w | 17 | ऽ | । | ॥ |
Virama: dedicated key, - (OEM_MINUS, sc 12): 0 12 0x94d. Conjuncts are 3 keystrokes — consonant, virama, consonant — same as real InScript, already confirmed correct and complete.
Digits: number-row keys, layer0=ASCII digit (unchanged), layer3(altgr)=Devanagari digit ०-९.
Compose-key hex stays the fallback for anything not on this table (Vedic accents, rare marks).
Script to generate mapping
# load Hindi phonetic kbmap table onto altgr/shiftaltgr/mod4/altgrmod4
# (layers 3/7/8/9) -- layers 0/1 (none/shift) are left untouched so
# plain typing and /dev/kbd's k-message stay pure ASCII.
# layer sc hex
while read -r layer sc hex; do
printf "%s %s '%s\n" "$layer" "$sc" "$hex"
done <<'EOF'
3 37 क
8 37 ख
3 34 ग
8 34 घ
3 46 च
8 46 छ
3 36 ज
8 36 झ
3 20 त
7 20 ट
8 20 थ
9 20 ठ
3 32 द
7 32 ड
8 32 ध
9 32 ढ
3 49 न
7 49 ण
3 25 प
3 33 फ
3 48 ब
8 48 भ
7 50 म
3 21 य
3 19 र
3 38 ल
3 17 व
3 31 स
7 31 ष
8 31 श
3 35 ह
3 16 ङ
3 45 ञ
3 30 अ
7 30 ा
8 30 आ
3 23 इ
7 23 ि
8 23 ई
9 23 ी
3 22 उ
7 22 ु
8 22 ऊ
9 22 ू
3 18 ए
7 18 े
8 18 ऐ
9 18 ै
3 24 ओ
7 24 ो
8 24 औ
9 24 ौ
3 44 ं
7 44 ँ
8 44 ः
9 44 ॐ
3 45 ऽ
7 17 ।
8 17 ॥
3 12 ्
3 2 १
3 3 २
3 4 ३
3 5 ४
3 6 ५
3 7 ६
3 8 ७
3 9 ८
3 10 ९
3 11 ०
EOF
Lessons Learnt
- Avoid using layers 0 and 1 while testing. Else you might need frequent restarts. Also, using kbmap command helps since it uses mouse (3rd button) to avoid restart.
References
- Man pages kbdfs
- Sample kbmap for Devanagari
Comments
Post a Comment