Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDetermine the keyboard's locale
DescriptionThis example shows how to determine the keyboard's locale in Visual Basic 6. It uses API functions to determine the keyboard type. The HowTo tells how to change the keyboard type.
Keywordslocale, language, internationalization
CategoriesSoftware Engineering, Windows
 
Thanks to Chris Wagg.

Periodically a timer uses the GetKeyboardLayout API function to get the keyboard's layout. It then uses the GetLocaleInfo function to figure out what language the keyboard is set for.

 
Private Sub Timer1_Timer()
    ' Display KeyBoard Locale
    ' (this is great code to put on a status bar!)
    Dim r&
    r = GetKeyboardLayout(DWL_ANYTHREAD) '0&
    If r <> KBLayout Then
        KBLayout = r
        r = Val("&H" & Right(Hex(r), 4)) ' lower 16bits
        Dim strng$, buffer As String * bufsize
        r = GetLocaleInfo(r, LOCALE_SLANGUAGE, buffer, _
            bufsize - 1)
        strng = buffer
        If Label1.Caption <> strng Then
            Label1.Caption = strng
        End If
    End If
End Sub
 
To change the keyboard locale while the program is running, open the Control Panel and run the Keyboard applet. Select the Language tab, click the Add button, and follow the instructions. After you have installed another language, you can decide what keyboard combination (LeftAlt-Shift, Ctrl-Shift, or None) lets you switch between languages.

The file KBLocale.txt contains some very interesting information on locales.

 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated