aqEnvironment.GetKeyboardLayout Method

Applies to TestComplete 15.69, last modified on November 13, 2024

Description

Use the GetKeyboardLayout method to get the identifier of the keyboard layout currently used for the needed window.

Declaration

aqEnvironment.GetKeyboardLayout(WindowHandle)

WindowHandle [in]    Required    Integer    
Result String

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

WindowHandle

Specifies the handle of the window whose active keyboard layout identifier you want to get. You can obtain this handle using the window’s Handle property.

Result Value

A string that contains the layout identifier for the specified window in a hexadecimal form. The full layout identifier string looks like “00000409” (US English), “00000407” (German), “0000040C” (French) and so on. The last four characters of the string specify the language identifier, for example: 0409 (the language ID of US English), 0407 (German), 040C (French). The first four characters of the string specify the device handler of the physical keyboard layout, for example, “00100409” (US English Dvorak layout).

To learn more about layout identifiers, see the description of the LoadKeyboardLayout function in Win32 API documentation.

Example

The following code demonstrates how you can check whether the desired keyboard layout is set for a process. If it is not set, the routine sets the layout for the process automatically.

JavaScript, JScript

function KeyboardLayoutExample()
 {
   WshShell.Run("notepad.exe", SW_NORMAL);
   var wNotepad = Sys.Process("notepad");
   var EditForm = wNotepad.Window("Notepad", "Untitled - Notepad", 1).Window("Edit", "", 1);
   var USEnglish = "00000409";
   if (aqEnvironment.GetKeyboardLayout(EditForm.Handle) != USEnglish)
   {
    if (aqEnvironment.SetKeyboardLayout(wNotepad.Id, USEnglish) == false)
    {
      Log.Error("The specified language is not supported.");
    }
   }
   EditForm.Keys("Hello!");
 }

Python

def KeyboardLayoutExample():
  WshShell.Run("notepad.exe", SW_NORMAL)
  wNotepad = Sys.Process("notepad")
  EditForm = wNotepad.Window("Notepad", "Untitled - Notepad", 1).Window("Edit", "", 1)
  USEnglish = "00000409"
  if aqEnvironment.GetKeyboardLayout(EditForm.Handle) != USEnglish:
    if aqEnvironment.SetKeyboardLayout(wNotepad.Id, USEnglish) == False:
      Log.Error("The specified language is not supported.")
  EditForm.Keys("Hello!")

VBScript

Sub KeyboardLayoutExample
   Dim wNotepad, EditForm, USEnglish
   Call WshShell.Run("notepad.exe", SW_NORMAL)
   Set wNotepad = Sys.Process("notepad")
   Set EditForm = wNotepad.Window("Notepad", "Untitled - Notepad", 1).Window("Edit", "", 1)
   USEnglish = "00000409"
   If Not (aqEnvironment.GetKeyboardLayout(EditForm.Handle) = USEnglish) Then
    If aqEnvironment.SetKeyboardLayout(wNotepad.Id, USEnglish) = False Then
      Log.Error("The specified language is not supported.")
    End If
   End If 
   EditForm.Keys("Hello!")
End Sub

DelphiScript

function KeyboardLayoutExample;
   var wNotepad, EditForm, USEnglish;
begin
   WshShell.Run('notepad.exe', SW_NORMAL);
   wNotepad := Sys.Process('notepad');
   EditForm := wNotepad.Window('Notepad', 'Untitled - Notepad', 1).Window('Edit', '', 1);
   USEnglish := '00000409';
   if aqEnvironment.GetKeyboardLayout(EditForm.Handle) <> USEnglish then
   begin
    if aqEnvironment.SetKeyboardLayout(wNotepad.Id, USEnglish) = False then
    begin
      Log.Error('The specified language is not supported.')
    end;
   end;
   EditForm.Keys('Hello!');
end;

C++Script, C#Script

function KeyboardLayoutExample()
 {
   WshShell["Run"]("notepad.exe", SW_NORMAL);
   var wNotepad = Sys["Process"]("notepad");
   var EditForm = wNotepad.Window("Notepad", "Untitled - Notepad", 1).Window("Edit", "", 1);
   var USEnglish = "00000409";
   if (aqEnvironment["GetKeyboardLayout"](EditForm.Handle) != USEnglish)
   {
    if (aqEnvironment["SetKeyboardLayout"](wNotepad["Id"]) == false)
    {
      Log["Error"]("The specified language is not supported.");
    }
   }
  EditForm["Keys"]("Hello!")
  }

See Also

Simulating Keystrokes
SetKeyboardLayout Method
IsLanguageSupported Method

Highlight search results