Click here to Skip to main content
Click here to Skip to main content

Changing Keyboard Layout

By , 29 Jun 2010
 

Introduction

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.

[DllImport("user32.dll")] 
private static extern long GetKeyboardLayoutName(System.Text.StringBuilder pwszKLID); 
[DllImport("user32.dll")] 
private static extern long LoadKeyboardLayout(string pwszKLID, uint Flags);

License

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

About the Author

Abdelmawgoud M. Meabed
Egypt Egypt
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 1memberkarabax29 Jun '10 - 14:10 

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

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