C# move mouse in other window

Started by
1 comment, last by x_maddog_x 7 years, 2 months ago

hi guys, i have created move mouse! but i need put only in one window

sample:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SendMessage(int hWnd, int msg, int wParam, IntPtr lParam);
int hwnd = FindWindow(null, "otherlocation");
SendMessage((int)hwnd, WM_RBUTTONDOWN, 0, IntPtr.Zero);
SendMessage((int)hwnd, WM_RBUTTONUP, 0, IntPtr.Zero);
this work by click! but i need move mouve in the "otherlocation"
QUESTION>>>
sample:
[DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y);
int PosX = Convert.ToInt32(textBox1.Text);
int PosY = Convert.ToInt32(textBox2.Text);
SetCursorPos(PosX, PosY);
(the sample i move mouse in my desk)

how i move mouse in the find window location?

Advertisement

Moving the mouse and clicking it?

I'm not entirely sure what you're up to. There are only a few good reasons to do it, like automating tests and such. There are plenty of nefarious reasons to do it.

Be aware that users strongly object to programs that move their mouse. Even jumping the mouse to the OK button on a form is generally too aggressive. As an automation thing it can be okay, but beware of doing it when the user is present.

You've already got the functions correct. SetCursorPos. Since you're in C# you can also use Windows.Forms.Cursor.Position().

Both take a position in SCREEN coordinates. If you're looking for an offset within a window location, there are the ClientToScreen() and ScreenToClient() functions. The C# equivalents are Windows.Forms.Control.PointToScreen() and ...PointToClient() functions.

i put this

int hwnd = FindWindow(null, "otherwindow");

SendMessage((int)hwnd, WM_MOUSEMOVE, PosX, IntPtr.Zero);

But mouse entry in the new window! "NICE!"

but in top page 0

how i add X or Y distance?

int PosY = "400"

int PosX = "400"

i want more codes. plz help me.

This topic is closed to new replies.

Advertisement