Jump to content
  • Advertisement
Sign in to follow this  

[.net] Mouse delta

This topic is 4747 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. I have just one quick question about mouse input. Is there a simple way to get the delta the mouse has moved? I tried using MouseMove event of control but it only returns absolute position of mouse cursor. I could use the difference from last position but it doesn't work when mouse is on border. I need to get delta even if for example mouse is on left side (x=0) and I move it a bit more left. Absolute position should stay the same but I need to get the amount the mouse has really moved. Any help would be useful. -Mirko

Share this post


Link to post
Share on other sites
Advertisement
I'm not sure if it'll help, but you can translate from absolute to client coordinates (with the top-left of your window being 0,0) by calling this from inside your Form:

Point clientCoords = this.PointToClient(Cursor.Position);

Share this post


Link to post
Share on other sites
I think you should look at the Control.Capture property, but then, it depends on what you want to achieve exactly.

(Capturing the mouse will allow you to receive MouseMove events, even if the mouse is moving outside your control).

Share this post


Link to post
Share on other sites
Thank you but I know about PointToClient and Capture and they don't help me much with my problem. I have no problem capturing mouse movements outside my control. I have a problem getting mouse movements that would end up outside the screen. Is there some kind of function to PInvoke to get this info. I'm looking for something that doesn't need some external library.

Share this post


Link to post
Share on other sites
DirectInput was giving you mouse delta (at least it did when I was using it :)

Without DirectX or any other external library I don't know if there's a good way of doing it. But there's always the ugly way :)
If you are doing an FPS, you could hide the cursor, place it at the center of the form and hold it there. That is, every loop you check the mouse position. If it's at the center of the form, delta is 0. Otherwise, calculate the delta and return the mouse to the center of the form.

I didn't try that, but it should work.

Share this post


Link to post
Share on other sites
In Windows the cursor is not allowed to leave the screen, that's why you can't get any delta when the user tries to.

If all you want is get the real mouse mouvement, i.e. you don't care about the cursor, the only way I know of is DirectInput, as Seroja said. I don't know any Win32 solution.

Good luck,
jods

Share this post


Link to post
Share on other sites
If you get the client coordinates of the mouse, you can check it against your form's ClientRectangle property to see if it was within the boundaries of your form. Is this what you mean by "outside the screen"?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!