PPT2000: Macro to Detect Keyboard Language (278957)



The information in this article applies to:

  • Microsoft PowerPoint 2000

This article was previously published under Q278957

SUMMARY

The Microsoft Visual Basic for Applications macro in this article demonstrates how to determine the keyboard language setting. You may need to determine this setting before you display a message or type characters in a shape.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
NOTE: The following macro examples work only in PowerPoint. Visual Basic for Applications macros are not supported by the Microsoft PowerPoint Viewer. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

Sample Code

  1. On the Tools menu, point to Macro, and then click Visual Basic Editor.
  2. On the Insert menu, click Module.
  3. Type the following code in the module:
    Option Explicit
    
    '
    ' Declare API calls.
    '
    Public Declare Function GetKeyboardLayout Lib "user32" _
          (ByVal dwLayout As Long) As Long
    '
    ' CopyMemory takes the value in Source, and extracts the byte
    ' values from the number of bytes indicated by Length from
    ' Source.
    '
    Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
          (Destination As Any, Source As Any, ByVal Length As Long)
    
    Function LowWord(ByVal lOriginalValue As Long) As Integer
    '
    ' Returns the low word of a Long value. Therefore, if GetKeyboardLayout
    ' returns the value 67699721, this function extracts the decimal
    ' value of the of the first word in the lOriginalValue variable, and
    ' returns 1033 as the value of the first word of lOriginalValue.
    '
    ' The Long data type is a 4-byte Integer that ranges in value from
    ' -2,147,483,648 to 2,147,483,647. A word is two bytes long.
    '
       CopyMemory LowWord, lOriginalValue, 2
    End Function
    
    Sub test()
       Dim lKeyboardValue As Long
       Dim lResp As Long
       Dim lLangCode As Long
       Dim strLang As String
    '
    ' Initialize lKeyboardValue to zero
    '
       lKeyboardValue = 0
    '
    ' Get the Keyboard Layout value.
    '
       lResp = GetKeyboardLayout(lKeyboardValue)
    '
    ' Extract the language code value.
    '
       lLangCode = LowWord(lResp)
    '
    ' Using the Select Case statement, match the code to one of the
    ' standard keyboard language types available to Microsoft Windows.
    '
       Select Case lLangCode
          Case 1028
             strLang = "Taiwan - Chinese, Traditional"
          Case 1029
             strLang = "Czech - Czech"
          Case 1030
             strLang = "Denmark - Danish"
          Case 1031
             strLang = "Germany - German"
          Case 1032
             strLang = "Greece - Greek"
          Case 1033
             strLang = "US - English"
          Case 1034
             strLang = "Spain - Spanish"
          Case 1035
             strLang = "Finland - Finnish"
          Case 1036
             strLang = "France - French"
          Case 1037
             strLang = "Israel - Hebrew"
          Case 1038
             strLang = "Hungary - Hungarian"
          Case 1040
             strLang = "Italy - Italian"
          Case 1041
             strLang = "Japan - Japanese"
          Case 1042
             strLang = "Korea - Korean"
          Case 1043
             strLang = "Benelux - Dutch"
          Case 1044
             strLang = "Norway - Norwegian"
          Case 1045
             strLang = "Poland - Polish"
          Case 1046
             strLang = "Brazil - Portuguese"
          Case 1049
             strLang = "Russia - Russian"
          Case 1051
             strLang = "Slovakia - Slovakian"
          Case 1053
             strLang = "Sweden - Swedish"
          Case 1054
             strLang = "Thailand - Thai"
          Case 1055
             strLang = "Turkey - Turkish"
          Case 1060
             strLang = "Slovenia - Slovenian"
          Case 2052
             strLang = "China - Chinese, Simplified"
          Case 2057
             strLang = "UK - English"
          Case 2060
             strLang = "Benelux - French"
          Case 2070
             strLang = "Portugal - Portuguese"
          Case 3081
             strLang = "Australia - English"
          Case 3084
             strLang = "Canada - French"
          Case 4105
             strLang = "Canada - English"
          Case 5129
             strLang = "New Zealand - English"
          Case 13321
             strLang = "Philippines - English"
          Case 14345
             strLang = "Indonesia - English"
          Case 15369
             strLang = "Hong Kong SAR - English"
          Case 16393
             strLang = "India - English"
          Case 17417
             strLang = "Malaysia - English"
          Case 18441
             strLang = "Singapore - English"
          Case 58378
             strLang = "LatAm - Spanish"
          Case 58380
             strLang = "North Africa - French"
          Case Else
             strLang = "Not listed"
       End Select
    '
    ' Display a Message box with the language code and name.
    '
       MsgBox "The Keyboard language is: " & lLangCode & ": " & strLang
    End Sub
    					

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbdtacode kbhowto KB278957