2

I'd like to simulate mouse click to a game and don't want my app take my mouse so I don't use mouve_event, I used SendMessage likes this:

int coordinates = clientPoint.Y << 16 | clientPoint.X;
SendMessage(wndHandle, WM_LBUTTONDOWN, 0, coordinates);
SendMessage(wndHandle, WM_LBUTTONUP, 0, coordinates);

I'd like to click on point X, Y but this code only clicks on last mouse position on my game.

How to make SendMessage click on point X, Y of my game?

Thank you all so much.

Duy
  • 21
  • 2
  • Did you tried moving the cursor position ? http://stackoverflow.com/a/7121314/555111 – Goufalite Apr 03 '17 at 06:14
  • Possible duplicate of [How to simulate Mouse Click in C#?](http://stackoverflow.com/questions/2416748/how-to-simulate-mouse-click-in-c) – Goufalite Apr 03 '17 at 06:16
  • I don't want using mouse_event because it moves my cursor. – Duy Apr 04 '17 at 00:39
  • Why are you shifting your y axis? – Sam Axe Apr 04 '17 at 01:04
  • lParam and wParam should be defined as int, because .NET long is 64-bit integer, and Win32 WPARAM and LPARAM are 32-bits type. To pack x and y to LPARAM I use LParam = (y << 16) | x; – Duy Apr 04 '17 at 01:11
  • Well, you are simulating a physical click on your mouse, so you physically have to move your cursor. What you could do is store the current position, move your cursor, click, and move your cursor to the previous stored position. – Goufalite Apr 04 '17 at 06:52

0 Answers0