how to programmatically install a keyboard layout?

Alan Sinclair 11 Reputation points
2020-10-21T19:49:20.803+00:00

I need to package several different keyboard layouts aka "input locale identifiers" together, so I need to write some code to install a layout in Windows, but haven't found any documentation. Can anyone show me example code or point me to documentation? Backgound: Microsoft's MSKLC tool enables creation of Keyboard Layouts. Each single layout is 'contained' in a DLL; for a layout MSKLC creates four DLLs for various flavors of Windows (naming them i386, amd64, ia64, wow64). MSKLC also creates the three appropriate MSI installers for that single layout, but those installers cannot be used in this situation. Just deploying the DLLs doesn't enable them, there is obviously some action needed to add the new locale identifiers to what Windows knows about its keyboards.

(I'm unsure this is the right place for this question, and what tags should be used .. please correct me if necessary)

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,426 questions
{count} vote

17 answers

Sort by: Most helpful
  1. Robert Sullivan 11 Reputation points
    2021-03-05T22:59:53.547+00:00

    You need to:
    -- Put your keyboard layout (the .dll) in \windows\system32

    Look at the following registry key:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layouts

    If you keyboard layout is a US / english layout look look at this key:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layouts\00000409

    You will pick a registry key name XXXX0409 where 'XXXX' is an unused registry key.
    I.e, 0001049 is the United States-Dvorak (look at its values), 00020409 is the United States-International,...

    I would not use a0000409 because that is what MSKLC typically uses. Perhaps 00060409 would be good.

    The last 4 characters of the string must always be the 'locale' (the language):
    0409 means US English
    0407 means German (Deutsch)

    Have you installer make the registry entry.

    By the way the Layout Display Name value (Like: @%SystemRoot%\system32\input.dll,-5000) is where the system
    is getting some information to display about the keyboard. I am assuming you are doing this in C++ (your keyboard layout).
    The default location for standard installed keyboard layouts is in input.dll.

    In your .rc for your keyboard layout include something like this:
    STRINGTABLE
    LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
    BEGIN
    1000 L"US(P)"
    1100 L"Custom English (United States)"
    1200 L"en-US"
    END

    The value for your registry keys 'Layout Display Name' value would then be
    @%SystemRoot%\system32\YourCustomName.dll,-1100

    After you have done this go to Settings->Time & Language->Language.

    Click on your language the keyboard is designed for under 'preferred languages'.
    Click on 'Options'
    Under 'Keyboards' click Add a keyboard.
    Find your custom keyboard in the list and add it.

    It will now be preloaded.

    If interested one can look at the following registry keys:
    HKEY_USERS.DEFAULT\Keyboard Layout
    This is where keyboard layout that are loaded at boot time are identified.

    HKEY_USERS.DEFAULT\Keyboard Layout
    This is where keyboard layouts that can be substituted within a language (i.e. 0409))

    I do not normally do the Settings-> thing for my keyboard layouts, but rather make the
    Preload and Substitute registry settings myself within a C++ installer (One cannot make these
    due to the quite complicated dance it requires cannot be performed via standard Installer Database commands).

    Hope this helps.

    You need to also have your Keyboard layout preloaded if you want it to appear

    0 comments No comments

  2. Davide Beatrici 1 Reputation point
    2021-03-21T04:43:11.023+00:00

    I've been working on a keyboard layout installer: https://github.com/davidebeatrici/kli

    Feel free to use it as reference.

    0 comments No comments