LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Automate mouse click event.

 
    I have an exe file, which is used to finish a series of tasks:just repeatedly move the mouse cursor and left-click mouse. I want to make this action automatically, so I'm seeking a way that I can fulfill mouse cursor move and left click action just in my CVI Program, rather than manually use my hand to do that. Is there any way to do this?

Thanks
Jacky
0 Kudos
Message 1 of 6
(4,954 Views)

Hello Jacky,

it is possible to change the position of the mouse cursor. Do to so, use the SetCursorPos function. This is a windows function, so you will have to include windows.h on top of your file. You will find more information here. Unfortunately I do not know any functions that simulate a mouse click, so I would simulate this by making the control active,  using SetActiveCtrl, and then using FakeKeyStroke to simulate the enter key. On buttons this will have the same effect as clicking your mouse.

I hope this helps you a little bit further.

Wim

Message Edited by Wim S on 07-13-2006 04:27 PM

0 Kudos
Message 2 of 6
(4,948 Views)

Then comes another question when trying to use "SetActiveCtrl(PanelHandle, ControlID)". Since that is an EXE file and we don't know its source codes, how can I get the panelhandle and control IDs?

 

Thanks!

Jacky

0 Kudos
Message 3 of 6
(4,932 Views)

Jacky,

one possible way to do what you want, supposing the left clicks are on controls that accept hotkeys, is to send the appropriate (simulated) keystrokes to the application via windows messages. You will find useful this discussion that covers this subject.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 6
(4,926 Views)
I'm sorry Jacky. I'm afraid I misunderstood the question Smiley Sad . If hotkeys are available, Roberto's idea seems like a good solution.
0 Kudos
Message 5 of 6
(4,916 Views)

Another possibility is SendInput SDK function, that can actually send mouse event messages to a running application. Thake a look at my post in this discussion: the code is to send keystrokes but SendInput function actually can send mouse events too. Please note also the warning at the end of my words: a particular #define is needed for SendInput to work that I cannot find defined on my machine.

According to this MSDN article, a value greater than 0x0400 is used for this #define on NT machines and over: since I'm working on a XP one I should have defined a value of 0x0501 or greater, so I should have no problems in using this command but that macro is not even defined on my system, so the question mark still remains.

Message Edited by Roberto Bozzolo on 07-14-2006 09:22 AM



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 6
(4,919 Views)