Click here to Skip to main content
16,023,339 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to control mouse position and click the mouse on buttons in a window on a 2nd monitor. I have tried several methods of controlling mouse position and clicking, but have not found a way to send the mouse to any monitor other than the primary monitor. I'm working with Visual Basic (.NET 2015).

What I have tried:

Private Sub OneClick_Click(sender As Object, e As EventArgs) Handles OneClick.Click

Dim Monitor As Object
Monitor = Screen.AllScreens(1).WorkingArea

SetCursorPos(299, 299)
mouse_event(M_LEFTDOWN, 0, 0, 0, 0)
mouse_event(M_LEFTUP, 0, 0, 0, 0)

End Sub
Posted
Updated 23-Jun-16 7:04am

1 solution

There is no difference what monitor you use, because you use it as a part of a virtual screen. That's why you get different WorkingArea objects. One monitor is continuation of another one. And in case you are using the mode when two monitors show identical image, it still makes no difference, by obvious reasons. So, click where you want it.

How to simulate the event? Here is how: SendInput function (Windows).

To do in in .NET, you use P/Invoke. It's all already done for you: http://www.pinvoke.net/default.aspx/user32.sendinput.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900