I'd like to perform a click in a windows application, without using the real mouse (so I can minimize it). Much like a bot would behave.
How would I do this?
You can right-click by holding down the left mouse button.
Some controls, like Button in System. Windows. Forms, have a "PerformClick" method to do just that. If the control doesn't have a PerformClick method, you can extend/add one, just needs to call OnMouseClick with a suitable MouseEventArgs argument.
The HTMLElement. click() method simulates a mouse click on an element. When click() is used with supported elements (such as an <input> ), it fires the element's click event. This event then bubbles up to elements higher in the document tree (or event chain) and fires their click events.
I think the function you're looking for is PostMessage
[DllImport("user32.dll", SetLastError = true)]
public static extern bool PostMessage(int hWnd, uint Msg, int wParam, int lParam);
You can read more about it here on codeproject, and download a demo project, which sends keystrokes.
This method posts messages directly on the input queue associated with the program, based on the process handle you use (hWnd)
You can also use this function to send mouse clicks with it, by posting button events, like so:
PostMessage(hWnd, WM_LBUTTONDBLCLK, 0, l);
More information about those button events can be found here on MSDN.
I'm sure if you search around the internet for samples for PostMessage mouse events you'll find plenty
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With