Jump to content
  • Advertisement
Sign in to follow this  
x_maddog_x

C# move mouse in other window

This topic is 591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!