Importkeyboard is a simple tool to convert a Windows keyboard layout to a Keyman keyboard source file.

Andrew Cunningham recently asked me if there was a facility in Keyman Developer 8.0 to generate a Keyman Desktop .kmn source file from a Windows keyboard layout.  This functionality is not included in Keyman Developer but in this post I'll make available a command-line tool that will do that very thing.

ImportKeyboard is straightforward to use.  If you pass no parameters, you'll be shown basic usage:

C:>importkeyboard
Usage: importkeyboard /list | [/kmw] hkl [output.kmn]

 /list shows a list of keyboards available on your system.

 hkl should be an 8 hex digit Keyboard ID.  See /list to enumerate these.
 /kmw should be specified to target KeymanWeb.  When using KeymanWeb, the imported keyboard will:
    * Ignore CAPS/NCAPS
    * Convert RALT to CTRL+ALT

 If output.kmn is not specified, the filename of the source keyboard will be used; e.g. 00000409 will produce kbdus.kmn

The /list option will display a list of the keyboards available on your system for import: 

C:>importkeyboard /list
     ID         Filename        Keyboard Name
  00000401      KBDA1.DLL       Arabic (101)
  00000402      KBDBU.DLL       Bulgarian
  00000404      KBDUS.DLL       Chinese (Traditional) – US Keyboard
  00000405      KBDCZ.DLL       Czech
  00000406      KBDDA.DLL       Danish
  00000407      KBDGR.DLL       German
  00000408      KBDHE.DLL       Greek
  00000409      KBDUS.DLL       US
  0000040a      KBDSP.DLL       Spanish
  0000040b      KBDFI.DLL       Finnish
  0000040c      KBDFR.DLL       French
  0000040d      KBDHEB.DLL      Hebrew
  0000040e      KBDHU.DLL       Hungarian
  0000040f      KBDIC.DLL       Icelandic
  00000410      KBDIT.DLL       Italian
  00000411      KBDJPN.DLL      Japanese
  00000412      KBDKOR.DLL      Korean
  00000413      KBDNE.DLL       Dutch
  00000414      KBDNO.DLL       Norwegian
  00000415      KBDPL1.DLL      Polish (Programmers)
  00000416      KBDBR.DLL       Portuguese (Brazilian ABNT)
  00000418      KBDRO.DLL       Romanian (Legacy)
  00000419      KBDRU.DLL       Russian
  0000041a      KBDCR.DLL       Croatian
  0000041b      KBDSL.DLL       Slovak
  0000041c      KBDAL.DLL       Albanian
  0000041d      KBDSW.DLL       Swedish
  0000041e      KBDTH0.DLL      Thai Kedmanee
  0000041f      KBDTUQ.DLL      Turkish Q
  00000420      KBDURDU.DLL     Urdu
  00000422      KBDUR.DLL       Ukrainian
  00000423      KBDBLR.DLL      Belarusian
  00000424      KBDCR.DLL       Slovenian
  00000425      KBDEST.DLL      Estonian
  00000426      KBDLV.DLL       Latvian
  00000427      KBDLT.DLL       Lithuanian IBM
  00000428      KBDTAJIK.DLL    Tajik
  00000429      KBDFA.DLL       Persian
    (snipped)

To import a keyboard, for example Tajik, use the following command:

C:>importkeyboard 00000428 tajik.kmn
Importing Windows system keyboard 00000428 to Keyman keyboard tajik.kmn

Let's have a look at what is produced.  This particular file is straightforward – it does not include deadkeys.

c
c Keyman keyboard generated by ImportKeyboard
c Imported: 26/07/2011 8:23:34 AM
c
c Source Keyboard File: KBDTAJIK.DLL
c Source KeyboardID: 00000428
c Target: Keyman Desktop
c
c

store(&Version) "8.0"
store(&Name) "Tajik"

begin Unicode > use(main)

group(main) using keys

+ [K_SPACE] > U+0020
+ [SHIFT K_SPACE] > U+0020
+ [CTRL K_SPACE] > U+0020

+ [K_0] > U+0030
+ [SHIFT K_0] > U+0029

+ [K_1] > U+0031
+ [SHIFT K_1] > U+0021

+ [K_2] > U+0032
+ [SHIFT K_2] > U+0022

+ [K_3] > U+0033
+ [SHIFT K_3] > U+2116

+ [K_4] > U+0034
+ [SHIFT K_4] > U+003b

+ [K_5] > U+0035
+ [SHIFT K_5] > U+0025

+ [K_6] > U+0036
+ [SHIFT K_6] > U+003a

+ [K_7] > U+0037
+ [SHIFT K_7] > U+003f

+ [K_8] > U+0038
+ [SHIFT K_8] > U+002a

+ [K_9] > U+0039
+ [SHIFT K_9] > U+0028

+ [NCAPS K_A] > U+0444
+ [CAPS K_A] > U+0424
+ [NCAPS SHIFT K_A] > U+0424
+ [CAPS SHIFT K_A] > U+0444

+ [NCAPS K_B] > U+0438
+ [CAPS K_B] > U+0418
+ [NCAPS SHIFT K_B] > U+0418
+ [CAPS SHIFT K_B] > U+0438

+ [NCAPS K_C] > U+0441
+ [CAPS K_C] > U+0421
+ [NCAPS SHIFT K_C] > U+0421
+ [CAPS SHIFT K_C] > U+0441

+ [NCAPS K_D] > U+0432
+ [CAPS K_D] > U+0412
+ [NCAPS SHIFT K_D] > U+0412
+ [CAPS SHIFT K_D] > U+0432

+ [NCAPS K_E] > U+0443
+ [CAPS K_E] > U+0423
+ [NCAPS SHIFT K_E] > U+0423
+ [CAPS SHIFT K_E] > U+0443

+ [NCAPS K_F] > U+0430
+ [CAPS K_F] > U+0410
+ [NCAPS SHIFT K_F] > U+0410
+ [CAPS SHIFT K_F] > U+0430

+ [NCAPS K_G] > U+043f
+ [CAPS K_G] > U+041f
+ [NCAPS SHIFT K_G] > U+041f
+ [CAPS SHIFT K_G] > U+043f

+ [NCAPS K_H] > U+0440
+ [CAPS K_H] > U+0420
+ [NCAPS SHIFT K_H] > U+0420
+ [CAPS SHIFT K_H] > U+0440

+ [NCAPS K_I] > U+0448
+ [CAPS K_I] > U+0428
+ [NCAPS SHIFT K_I] > U+0428
+ [CAPS SHIFT K_I] > U+0448

+ [NCAPS K_J] > U+043e
+ [CAPS K_J] > U+041e
+ [NCAPS SHIFT K_J] > U+041e
+ [CAPS SHIFT K_J] > U+043e

+ [NCAPS K_K] > U+043b
+ [CAPS K_K] > U+041b
+ [NCAPS SHIFT K_K] > U+041b
+ [CAPS SHIFT K_K] > U+043b
(snipped)

When creating a keyboard for KeymanWeb, it is useful to include the /kmw command line option.  This modifies the output to avoid NCAPS and CAPS references, and converts any AltGr rules to Ctrl+Alt, as neither of these scenarios are supported by KeymanWeb.

The importkeyboard tool also supports deadkeys.  These will be added in a separate group at the end of the file, for example with French AZERTY (some lines removed from this example):

group(main) using keys)

+ [NCAPS RALT K_2] > dk(007e)
+ [NCAPS RALT K_7] > dk(0060)
+ [NCAPS K_LBRKT] > dk(005e)
+ [CAPS K_LBRKT] > dk(00a8)
+ [NCAPS SHIFT K_LBRKT] > dk(00a8)
+ [CAPS SHIFT K_LBRKT] > dk(005e)

match > use(deadkeys)

group(deadkeys)

store(dkf007e) U+0020 U+0061 U+0041 U+006e U+004e U+006f U+004f
store(dkt007e) U+007e U+00e3 U+00c3 U+00f1 U+00d1 U+00f5 U+00d5
dk(007e) any(dkf007e) > index(dkt007e, 2)

store(dkf0060) U+0020 U+0061 U+0041 U+0065 U+0045 U+0069
               U+0049 U+006f U+004f U+0075 U+0055

store(dkt0060) U+0060 U+00e0 U+00c0 U+00e8 U+00c8 U+00ec
               U+00cc U+00f2 U+00d2 U+00f9 U+00d9

dk(0060) any(dkf0060) > index(dkt0060, 2)

store(dkf00a8) U+0020 U+0061 U+0041 U+0065 U+0045 U+0069
               U+0049 U+006f U+004f U+0075 U+0055 U+0079

store(dkt00a8) U+00a8 U+00e4 U+00c4 U+00eb U+00cb U+00ef
               U+00cf U+00f6 U+00d6 U+00fc U+00dc U+00ff

dk(00a8) any(dkf00a8) > index(dkt00a8, 2)

store(dkf005e) U+0020 U+0061 U+0041 U+0065 U+0045 U+0069
               U+0049 U+006f U+004f U+0075 U+0055

store(dkt005e) U+005e U+00e2 U+00c2 U+00ea U+00ca U+00ee
               U+00ce U+00f4 U+00d4 U+00fb U+00db

dk(005e) any(dkf005e) > index(dkt005e, 2)

This secondary group runs after any keystroke, and when a deadkey and character pair is detected, outputs the correct character.  This behaviour is not identical to Windows deadkeys:  Windows' default behaviour when a deadkey does not match on the second key is to output both the default value for the deadkey and the second character, whereas unmatched second keys in the Keyman keyboard will simply cause the deadkey to be ignored.  However, this behaviour should be close enough for most uses.

Once you have created your keyboard, you can of course load it into Keyman Developer and edit it further there.  Creating the On Screen Keyboard is as easy as pressing the Fill from layout button:

Fillfromlayout

And there you have it.  Importkeyboard.exe requires .NET framework 2.0 to run.

Download importkeyboard.exe

 

Usage: importkeyboard /list | [/kmw] hkl [output.kmn]
 /list shows a list of keyboards available on your system.

 hkl should be an 8 hex digit Keyboard ID.  See /list to enumerate these.
 /kmw should be specified to target KeymanWeb.  When using KeymanWeb, the imported keyboard will:
    * Ignore CAPS/NCAPS
    * Convert RALT to CTRL+ALT

 If output.kmn is not specified, the filename of the source keyboard will be used; e.g. 00000409 will produce kbdus.kmn

Categories: Developing Keyboards

0 thoughts on “How to import a Windows keyboard layout into a Keyman Desktop keyboard”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts

Developing Keyboards

Introducing the Keyman Open Source Keyboard Repository

We have many hundreds of keyboard layouts online at keyman.com that cover well over a thousand  languages. These keyboard layouts work on Windows, the web, iPhones, iPads and Android phones and tablets. However, most of Read more…

Android

Using Keyman Engine for Android to create a system keyboard

In part 1 of this series, we looked at the steps involved in creating a basic Android app which included a Keyman in-app keyboard. In this post, we’ll work with the second sample included in Read more…