Setting HotKey Text in Desktop Windows Applications

Applies to TestComplete 15.47, last modified on January 20, 2023

While testing HotKey controls, you can use specific properties and methods of the corresponding program object to perform certain actions and obtain data stored in controls. You can call these methods and properties from your keyword tests, as well as from scripts. This topic describes how to work with the needed properties and methods from your scripts. However, when testing a control from your keyword test, you can use the same methods and properties calling them from keyword test operations. For more information, see Keyword Tests Basic Operations.

You can set a key or a key combination in the HotKey control by doing one of the following:

  • Assign a value to the wText property of the Win32HotKey object. During the test run, this object is automatically associated with HotKey controls whose class names are listed in the project's Object Mapping options. wText specifies the text displayed in the HotKey control.

    The string that you assign to the wText property corresponds to one key or key combination that can be used as a shortcut. A key combination can consist of one or several system keys, letter and numeric keys separated by a plus sign. The name of a numeric key can have two forms. It can consist of one number that corresponds to the numeric key. A numeric key's name consists of the word "Num", space and number. For instance, the string "Num 5" corresponds to the 5 key located on the numeric keypad.

    Below is an example that demonstrates how you can specify text in the HotKey control:

    JavaScript, JScript

    function main()
    {
      var HotKey;
        
      // Obtain the HotKey control
      HotKey = Sys.Process("Project1").Window("TForm1", "Form1", 1).Window("THotKey", "", 1);
      
      // Set the text
      HotKey.wText = "Ctrl+G"
    }

    Python

    def Main():
        
      # Obtain the HotKey control
      HotKey = Sys.Process("Project1").Window("TForm1", "Form1", 1).Window("THotKey", "", 1)
      
      # Set the text
      HotKey.wText = "Ctrl+G"

    VBScript

    Sub main
      Dim HotKey
        
      ' Obtain the HotKey control
      Set HotKey = Sys.Process("Project1").Window("TForm1", "Form1", 1).Window("THotKey", "", 1)

      ' Set the text
      HotKey.wText = "Ctrl+G"
    End Sub

    DelphiScript

    procedure main;
    var HotKey;
    begin

      // Obtain the HotKey control
      HotKey := Sys.Process('Project1').Window('TForm1', 'Form1', 1).Window('THotKey', '', 1);

      // Set the text
      HotKey.wText := 'Ctrl+G';
    end;

    C++Script, C#Script

    function main()
    {
      var HotKey;
        
      // Obtain the HotKey control
      HotKey = Sys["Process"]("Project1")["Window"]("TForm1", "Form1", 1)["Window"]("THotKey", "", 1);

      // Set the text
      HotKey["wText"] = "Ctrl+G";
    }

  • Simulate keystrokes with the Keys action (for more information, see the Simulating Keystrokes topic). To simulate simultaneous pressing of several keys, use the [Hold] constant.

    Here is an example:

    JavaScript, JScript

    function main()
    {
      var HotKey;
        
      // Obtain the HotKey control
      HotKey = Sys.Process("Project1").Window("TForm1", "Form1", 1).Window("THotKey", "", 1);
      
      // Set the text
      HotKey.Keys("[Hold]!g");
    }

    Python

    def Main():
        
      # Obtain the HotKey control
      HotKey = Sys.Process("Project1").Window("TForm1", "Form1", 1).Window("THotKey", "", 1)
      
      # Set the text
      HotKey.Keys("[Hold]!g")

    VBScript

    Sub main
      Dim HotKey
        
      ' Obtain the HotKey control
      Set HotKey = Sys.Process("Project1").Window("TForm1", "Form1", 1).Window("THotKey", "", 1)

      ' Set the text
      HotKey.Keys"[Hold]!g"
    End Sub

    DelphiScript

    procedure main;
    var HotKey;
    begin

      // Obtain the HotKey control
      HotKey := Sys.Process('Project1').Window('TForm1', 'Form1', 1).Window('THotKey', '', 1);

      // Set the text
      HotKey.Keys('[Hold]!g');
    end;

    C++Script, C#Script

    function main()
    {
      var HotKey;
        
      // Obtain the HotKey control
      HotKey = Sys["Process"]("Project1")["Window"]("TForm1", "Form1", 1)["Window"]("THotKey", "", 1);

      // Set the text
      HotKey["Keys"]("[Hold]!g");
    }

See Also

Working With HotKey Controls in Desktop Windows Applications
wText Property (HotKey Controls)

Highlight search results