Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // You can't do that by sending messages, instead use mouse_event Windows API, here is the code :
- // Call method ClickOnPoint, this is an example from form click event, so this.handle is form handle, note that these are client coordinates on window witch handle is send, you can easily change this and send screen coordinates, and in that case you don't need handle or ClientToScreen call below.
- ClickOnPoint(this.Handle, new Point(375, 340));
- // Code:
- private void ClickOnPoint(IntPtr wndHandle, Point clientPoint)
- {
- var oldPos = Cursor.Position;
- /// get screen coordinates
- ClientToScreen(wndHandle, ref clientPoint);
- /// set cursor on coords, and press mouse
- Cursor.Position = new Point(clientPoint.X, clientPoint.Y);
- mouse_event(0x00000002, 0, 0, 0, UIntPtr.Zero); /// left mouse button down
- mouse_event(0x00000004, 0, 0, 0, UIntPtr.Zero); /// left mouse button up
- /// return mouse
- Cursor.Position = oldPos;
- }
- // Declarations :
- [DllImport("user32.dll")]
- static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, UIntPtr dwExtraInfo);
- [DllImport("user32.dll")]
- static extern bool ClientToScreen(IntPtr hWnd, ref Point lpPoint);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement