Forum Discussion

vijay6105's avatar
vijay6105
Contributor
13 years ago

simulate pressing a mouse button

Hi,

 

I hava to simulate pressing a mouse button at a specific object in the window application. Is there any method for doing left pressing of mouse button on specific object?



There is MouseDown method which takes screen X,Y coordinates - MouseDown Method (Desktop Objects)



  
  • AlexeyK's avatar
    AlexeyK
    SmartBear Alumni (Retired)

    Vijay,


    Every test object that corresponds to a window or control contains the Click method that simulates a mouse click at object-specific coordinates. Test objects that correspond to specific control types (buttons, list views, list boxes, etc.) contain specific methods for simulating mouse clicks on an appropriate object (like ClickButton, ClickItem, etc.).


    You can record a test with your application and look at the recorded test commands to see how TestComplete simulates mouse clicks. See also Simulating Mouse Actions and Simulating User Actions in TestComplete help.

  • Hello,



    I've seen there are action methods for doing mouse clicks like click,drag, drop, hovermouse etc... But I want to do mouse left button press it and hold for some time(10 sec).It is not like click, it is pressing left mouse button for some time. There is 'MouseDown' method which does for the desktop objects. Similarly I want to know is there anything for windows objects 
  • AlexeyK's avatar
    AlexeyK
    SmartBear Alumni (Retired)

    Vijay,


    I see. The MouseDown method is available only for the Desktop object. As you said, this method works with screen coordinates. You need to convert window coordinates to screen coordinates before calling this method. For the conversion, use the WindowToScreen method of your window object.




    ...

    Set pointObj = MyWindowObject.WindowToScreen(10, 10)  ' Convert coordinates

    Call Sys.Desktop.MouseDown(VK_LBUTTON, pointObj.X, pointObj.Y) ' Call the MouseDown method

    ...

    • Charles_Liao's avatar
      Charles_Liao
      New Contributor
      Hello, AlexxeyK I'm new about TC. And I have the same requirement, and I try to write a PressMouse sub in a script, but I get a error when I try. As picture shown below. How should I correct it? Thanks!