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: Oldest
  1. Alan Sinclair 11 Reputation points
    2020-10-28T01:04:54.293+00:00

    > What kind of project are you using?

    WiX Toolset and Visual Studio 2017 writing C++ code.

    Using the WiX Toolset I'm making an MSI install package to deploy an input locale definition file; for reference I'll call that file LOCALE.DLL

    LOCALE.DLL is created by MSKLC to define the new keyboard layout. The specific language will already be installed on the target system; this new input locale remaps various keys for our specific needs. Msiexec.exe (the native Windows Installer) will install LOCALE.DLL from my MSI file.

    My MSI needs a custom action written in C++ using Visual Studio 2017

    As msiexec deploys LOCALE.DLL from my MSI, msiexec will call functions in a custom action binary (for reference I'll call this binary CUSTOM.DLL) which in turn calls WINAPI functions to "activate" the input locale: e.g. to add the keyboard configuration defined in LOCALE.DLL to the Windows Language Bar, etc. (CUSTOM.DLL is not deployed on the target system; it remains embedded in the MSI)

    For what it's worth, I'm familiar with writing custom action DLLs for Windows Installer; what I'm missing is how to activate the input locale provided in LOCALE.DLL which my MSI deploys.

    I think CUSTOM.DLL will need to use LoadKeyboardLayout and ActivateKeyboardLayout WINAPI functions but I have not found documentation

    Any pointers to documentation or example code you can give will be much appreciated!

    Thanks


  2. Alan Sinclair 11 Reputation points
    2020-10-28T19:45:56.92+00:00

    Sorry, I confused the issue. This is NOT about the Wix Toolset.

    I am asking what C++ code do I write to install an input locale (aka keyboard layout).

    Please can you give me a pointer to C++ or WINAPI documentation or example code for how to install an input locale?

    (The wix tool is just a deployment mechanism and not really relevant to my question. I mentioned it to give the full background, but it's unnecessary. I can use a C++ exe if you tell me where to find example or documentation.)

    thanks

    0 comments No comments

  3. Drake Wu - MSFT 991 Reputation points
    2020-10-29T06:28:48.37+00:00

    Hi @Alan Sinclair Please check if this Keyboard Layout Samples and the steps in it are what you need.


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

  4. Alan Sinclair 11 Reputation points
    2020-11-09T20:26:40.827+00:00

    @Drake Wu - MSFT
    Thanks DrakeWu .. the link gives samples of how to create new Keyboard Layouts, but what I need is example of how to USE a new layout -- i.e. how to install the new layout in Windows.

    Is there any example code to use LoadKeyboardLayout API, and/or ActivateKeyboardLayout API ?

    thanks
    Alan


  5. Robert Sullivan 11 Reputation points
    2020-11-20T17:13:01.333+00:00

    There has to be more to it than what Drake-WU has described.

    What does 'add the corresponding key value according to other layouts' mean?

    I created a Keyboard Layout with MKLSC. The install package calls out to an imbedded Custom.dll to perform some registry operations.
    The installed keyboard appears within the 'Language Bar'.

    I created a Keyboard layout from the Sample Keyboard Layouts (KBDUS.dll), ClientUs.dll.
    'Installed' it following your suggestion (I think?)

    'add the corresponding key value according to other layouts':
    I modeled the registry values under [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layouts\00060409]
    after the registry values for [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layouts\00000409].
    Is this what you mean?

    HKEY_CURRENT_USER\Keyboard Layout\Substitutes has a REG_SZ entry for d0020409 with a value of 00060409
    HKEY_CURRENT_USER\Keyboard Layout\Preload has a REG_SZ entry for 3 with a value of d0020409

    Note: I picked 00060409 arbitrarily.

    My Keyboard Layout shows up in Settings->Time & Language->Language->English->Options->Add a keyboard.
    I can add the keyboard.
    I can load the layout via LoadKeyBoardLayout("00060409").

    My Keyboard Layout does not show in the 'Language Bar'.

    Does something additional need to occur for an install to show up in the 'Language Bar'?

    Thanks

    0 comments No comments