Click here to Skip to main content
12,759,875 members (30,285 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


9 bookmarked
Posted 27 Jun 2010

Changing Keyboard Layout

, 29 Jun 2010 CDDL
Rate this:
Please Sign up or sign in to vote.
Programmatically switch keyboard layout in C#


In general, developers want to set the layout of keyboard prior to application localized language. In this demonstration, I will develop a simple Windows application with custom control in type of text box. So, we can make the default input language of this text box as property.

Using the Code

The code is separated into two parts, one of them deals with keyboard layout and the other is a client which tests this.

  1. For better performance, get the machine installed language as follows:
    public static InputLanguage GetInputLanguageByName(string inputName) 
        foreach (InputLanguage lang in InputLanguage.InstalledInputLanguages) 
            if (lang.Culture.EnglishName.ToLower().StartsWith(inputName)) 
                return lang; 
        return null; 
  2. Set your preferred language at run time:
    public void SetKeyboardLayout(InputLanguage layout) 
    InputLanguage.CurrentInputLanguage = layout; 

Remember the last used language before leaving the control if you intend to put editing controls with a different language in the same Windows Form.

Points of Interest

In the previous version of changing keyboard layout in this applicatoin, the code below was used.

The disadvantage of this is that importing external DLLs in the applications slows down the applications on Windows 7.

private static extern long GetKeyboardLayoutName(System.Text.StringBuilder pwszKLID); 
private static extern long LoadKeyboardLayout(string pwszKLID, uint Flags);


This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)


About the Author

No Biography provided

You may also be interested in...

Comments and Discussions

QuestionFull code that is missing in article Pin
Angelic Care4-Feb-12 14:28
memberAngelic Care4-Feb-12 14:28 
AnswerRe: Full code that is missing in article Pin
Amer Bakeer12-Jul-14 12:25
memberAmer Bakeer12-Jul-14 12:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 29 Jun 2010
Article Copyright 2010 by Abdelmawgoud M. Meabed
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid