Jump to content
  • Advertisement
Sign in to follow this  
dk32321

SetMousePostion

This topic is 4815 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

If there is a way in c++ set and and find location of mouse click, and is it possible to move object if you click and hold in c++, please help my life depends on it. peace homie

Share this post


Link to post
Share on other sites
Advertisement
Yes, it depends on your API of choice. If you're doing Win32 programming, look into intercepting the WM_MOUSEDOWN, WM_MOUSEMOVE and WM_MOUSEUP events. The parameters sent along them are the coordinates of the mouse.

If you're using SDL you can also process the analogous events. wxWidgets provides callbacks for the events but for individual mouse buttons (EVT_LEFTDOWN, EVT_LEFTUP) and uses EVT_MOTION for the mouse move event.

In DirectInput you can check the state of the mouse using the appropriate function and determine if the buttons are up or down. If the button is down and it was up the previous frame then an MOUSEDOWN event has occured and in a similar fasion you detect an MOUSEUP. You can also get the coordinates of the mouse easily.

Share this post


Link to post
Share on other sites
Under what operating system? This is not a C++ question. How you deal with cursors and mice is dependent on the platform you are using.

Share this post


Link to post
Share on other sites
C++ doesn't have any kind of built in way of accessing the mouse (or for that matter the keyboard particularly directly). So you have to use some kind an API appropriate to whatever OS you're using, unless its DOS or something else where you can do direct hardware access in which case you have to program code for a serial mouse, PS/2 mouse and a USB HID driver. You don't want to go there.

Share this post


Link to post
Share on other sites
Most compilers allow for the use of inline assembly, which you can use without headers. The syntax for that depends on your compiler.

Share this post


Link to post
Share on other sites
POINT MousePos;
GetCursorPos(&MousePos);

With GetCursorPos you will fill POINT structure MousePos witch have x and y position of the cursor.

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!