Why won't simulated mouse click at X Y coordinates like a real mouse click?

chuckchuckit

Well-known Member
Joined
Sep 18, 2010
Messages
541
Is the only way to get a simulated mouse to click on the screen, is to go through window handles, setfocus, mouse_event etc?

Can't we somehow just use the same interrupt system the physical left button on the mouse uses when this left button is clicked by a user, and then use the mouse coordinates X Y on the screen just like the physical mouse system does?

Going through window handles etc is prone to many problems, and does not always click when it should such as applications with embedded menu codes.

Thanks.
Chuck
 
Last edited:
It looks like this line that fails (returns 0) has to be resolved before any clicking will be possible:

Code:
Rtn = PostMessage(Gear_WinHndl, WM_SETFOCUS, 0&, 0&)
Unless someone knows why that line fails, I am thinking a way to resolve this will be to learn how to capture Windows messages, then do an actual "manual click" of the gear (which does work), and then look at the Windows messages generated by the successful manual click.

Then perhaps duplicate those messages in order to simulate a successful click.

Does anyone know how to capture Windows messages after a click?

Thanks.
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
For VBA code to simulate mouse clicks and (key presses), I can thoroughly recommend SendKeys.

Although I've only used (very successfully) the functions which emulate and improve the standard VBA SendKeys command, I'm positive that the mouse click functions will also work consistently and reliably. In my search for a better SendKeys, I found and tried many pieces of code and this was by far the best.

You need to download the VB6 version of the code and use the SendKeys.bas file. Although it is written in VB, it is very easy to convert to VBA.
 
Upvote 0
John, Thanks for the post and the VB6 updated SendKeys info. Looks like good possibilities as goes right into the problems with Window "Focus" of other applications outside Excel. Also has WINFOCUS structure for troubleshooting perhaps. Haven't downloaded it yet I'll be working on what you sent this weekend.

If "focus" succeeds then next, it also seems to be capable of AttchThreadInput (no doubt via GetWindowThreadProcessId) for use with external applications to then do that successful final click.

Been starting to look into hook and unhook keyboard/mouse which it also has.I was just starting to research API Windows messaging system to help find where problem is, SendKeys will save a lot of time if it works.

Appreciate the info, and anything else you may wish to add is of course welcome.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top