Click here to Skip to main content
13,397,892 members (43,706 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


9 bookmarked
Posted 28 Jun 2010

Changing Keyboard Layout

, 29 Jun 2010
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

GeneralMy vote of 1 Pin
yoke14-Sep-12 15:01
memberyoke14-Sep-12 15:01 
GeneralMy vote of 3 Pin
Burak Tunçbilek11-Aug-12 4:54
memberBurak Tunçbilek11-Aug-12 4:54 
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 
QuestionWell worth 5! Pin
JohnStodden24-Jan-12 2:56
memberJohnStodden24-Jan-12 2:56 
QuestionMy vote of 5 Pin
Member 76951445-Jul-11 23:38
memberMember 76951445-Jul-11 23:38 
GeneralMy vote of 4 Pin
lmkdev15-Jul-10 23:49
memberlmkdev15-Jul-10 23:49 
GeneralRe: My vote of 4 Pin
Abdelmawgoud M. Meabed6-Jul-11 1:45
memberAbdelmawgoud M. Meabed6-Jul-11 1:45 
GeneralMy vote of 2 Pin
Michael B. Hansen30-Jun-10 3:59
memberMichael B. Hansen30-Jun-10 3:59 
GeneralMy vote of 1 Pin
karabax29-Jun-10 15:10
memberkarabax29-Jun-10 15:10 
GeneralMy vote of 5 Pin
Member 475607928-Jun-10 20:49
memberMember 475607928-Jun-10 20:49 
GeneralMy vote of 5 Pin
abdelmogod28-Jun-10 20:05
memberabdelmogod28-Jun-10 20:05 
GeneralMy vote of 1 Pin
emilio_grv28-Jun-10 2:28
memberemilio_grv28-Jun-10 2:28 
GeneralRe: My vote of 1 Pin
Johnny J.28-Jun-10 22:05
memberJohnny J.28-Jun-10 22:05 
GeneralRe: My vote of 1 Pin
emilio_grv28-Jun-10 22:30
memberemilio_grv28-Jun-10 22:30 
GeneralNot an article. Pin
digital man28-Jun-10 1:54
memberdigital man28-Jun-10 1:54 
GeneralRe: Not an article. Pin
Johnny J.28-Jun-10 22:09
memberJohnny J.28-Jun-10 22:09 

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
Web04 | 2.8.180216.1 | Last Updated 29 Jun 2010
Article Copyright 2010 by Abdelmawgoud M. Meabed
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid