MouseDown Method (Desktop Objects)

Applies to TestComplete 14.40, last modified on April 22, 2021

Description

Use this method to simulate pressing a mouse button at a point with the specified screen coordinates.

Declaration

TestObj.MouseDown(VKXY)

TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section
VK [in]    Required    Integer    
X [in]    Required    Integer    
Y [in]    Required    Integer    
Result None

Applies To

The method is applied to the following object:

View Mode

To view this method in the Object Browser panel and in other panels and dialogs, activate the Advanced view mode.

Parameters

The method has the following parameters:

VK

Specifies the button to be pressed. You can use the following values for the parameter:

Constant Value Description
VK_LBUTTON 1 The left mouse button.
VK_RBUTTON 2 The right mouse button.
VK_MBUTTON 4 The middle mouse button.

If the Win32API plugin is installed in TestComplete, you can refer to the constants using their names without defining them in scripts.

X

The screen-relative horizontal coordinate of the pixel at which pressing the mouse button will be simulated.

Y

The screen-relative vertical coordinate of the pixel at which pressing the mouse button will be simulated.

Result Value

None.

Remarks

Unlike Click, ClickM, ClickR, DblClick, DblClickM and DblClickR, the MouseDown method does not interact with the tested application. This makes the method useful for testing specific ActiveX controls.

To release the mouse button, use the MouseUp method.

Example

The following example demonstrates how you can use the MouseDown method in your script:

JavaScript, JScript

function MouseClickExample()
{
  // Specifies the coordinates of the click
  var coordX = 150;
  var coordY = 300;
  
  // Simulates pressing the left mouse button
  Sys.Desktop.MouseDown(MK_LBUTTON, coordX, coordY);
  // ...
  // Simulates releasing the left mouse button
  Sys.Desktop.MouseUp(MK_LBUTTON, coordX, coordY);
}

Python

def MouseClickExample():
  # Specifies the coordinates of the click
  coorX = 150
  coorY = 300
  # Simulates pressing the left mouse button
  Sys.Desktop.MouseDown(MK_LBUTTON, coorX, coorY)
  # Simulates releasing the left mouse button
  Sys.Desktop.MouseUp(MK_LBUTTON, coorX, coorY)

VBScript

Sub MouseClickExample()

  ' Specifies the coordinates of the click
  coordX = 150
  coordY = 300
  
  ' Simulates pressing the left mouse button
  Call Sys.Desktop.MouseDown(MK_LBUTTON, coordX, coordY)
  ' ...
  ' Simulates releasing the left mouse button
  Call Sys.Desktop.MouseUp(MK_LBUTTON, coordX, coordY)
  
End Sub

DelphiScript

function MouseClickExample;
var coordX, coordY;
begin
  // Specifies the coordinates of the click
  coordX := 150;
  coordY := 300;
  
  // Simulates pressing the left mouse button
  Sys.Desktop.MouseDown(MK_LBUTTON, coordX, coordY);
  // ...
  // Simulates releasing the left mouse button
  Sys.Desktop.MouseUp(MK_LBUTTON, coordX, coordY);
end;

C++Script, C#Script

function MouseClickExample()
{
  // Specifies the coordinates of the click
  var coordX = 150;
  var coordY = 300;
  
  // Simulates pressing the left mouse button
  Sys["Desktop"]["MouseDown"](MK_LBUTTON, coordX, coordY);
  // ...
  // Simulates releasing the left mouse button
  Sys["Desktop"]["MouseUp"](MK_LBUTTON, coordX, coordY);
}

See Also

MouseUp Method (Desktop Objects)
Click Action
ClickR Action
ClickM Action
DblClick Action
DblClickR Action
DblClickM Action

Highlight search results