Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21266

simulate mouse click when the target window is in background

$
0
0
I've been doing a lot of automation lately. In some cases I can't avoid using simulated mouse clicks. Unfortunately at my workplace there are programs which randomly pop up to steal the focus and ruin my program.

I can use this code to send a click to a specific UI element if I know it's handle even if it's in background.

Code:

Call SendMessage(cmb, WM_LBUTTON_DOWN, ByVal 0&, 0&)
Call SendMessage(cmb, WM_LBUTTON_UP, ByVal 0&, 0&)

Unfortunately there some UI elements (toolboxes) the handles of which I can't find out, or sometimes sendmessage doesn't trigger the event I need. In these cases I use this:

Code:

  SetCursorPos 800, 200 'x and y position
  mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
  mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0

However for this to work the target window has to be on top. (or the part where I click should be visible on the screen) I would like to have a code which does the same as this, but the click would only go to the program with the handle I specify.

Thanks

Viewing all articles
Browse latest Browse all 21266

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>