cancel
Showing results for 
Search instead for 
Did you mean: 

simulate pressing a mouse button

Contributor

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)



  
7 REPLIES 7
Staff

RE: simulate pressing a mouse button

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.

I’m not a member of the SmartBear Support Team, I’m just helping users in this community.
Any views or opinions expressed do not necessarily represent those of SmartBear Software.

-----
Contributor

RE: simulate pressing a mouse button

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 
Staff

RE: simulate pressing a mouse button

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

...

I’m not a member of the SmartBear Support Team, I’m just helping users in this community.
Any views or opinions expressed do not necessarily represent those of SmartBear Software.

-----
New Contributor

Re: RE: simulate pressing a mouse button

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!
Community Hero

Re: RE: simulate pressing a mouse button

First of all... this thread is 7 years old...  Might be better to have posted your own question since there is no guarentee, after 7 years, that the original people are still around.

That said... Since you're using the Desktop object MouseDown method, you have the wrong number of parameters.  See https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/desktop/mousedown-met...

 

Remove the ms parameter and you should be good.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
New Contributor

Re: RE: simulate pressing a mouse button

Thanks for reply!
Because the the problem of network, I have simetime can not acess community. 
I have solved this problem. 
The LLPlayer.mouseDown method actually must have 4 parameters including ms and the ms parameter is the delay between Mouse Down and the last action instead of the delay during mouse press.
The sys.desktop.mouseDown method must have 3 parameters except ms. This makes me confused and we should note...

 

Community Hero

Re: RE: simulate pressing a mouse button

Correct.... there are two MouseDown methods depending upon what the parent object is.  The Deskstop.MouseDown is simply for simulating clicking down on a mouse on a place on screen.  LLPlayer.MouseDown comes from the Low-Level player which ties more closely into the low-level drivers of the Windows OS.  Both methods are documented...  I linked in the Desktop one... here's the LLPlayer one.

https://support.smartbear.com/testcomplete/docs/reference/project-objects/items/llp/llplayer/mousedo...

 

Making sure you're using the correct method is always a bonus.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
New Here?
Join us and watch the welcome video:
6 / 7 API Testing Mistakes Video
Top Kudoed Authors