Jump to content
  • Advertisement
Sign in to follow this  
gothicly

Checking for Mouse Input? (C++)

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

I'm working on a little game engine, but I'm having trouble getting mouse input..

All I want right now is to determine whether the mouse is clicked or not because I have code for reading mouse coordinates already.

I figured I could use the same style of code as I did for my keyboard events but I cannot seem to find the right code for mouse events.

In a void I have the key events:

if (KEYDOWN(VK_ESCAPE))
Quit();

if (KEYDOWN(VK_RETURN))
{
mouseOn = true;
}

if (KEYDOWN(VK_SHIFT))
{
mouseOn = false;
}


That code works for disabling/enabling the mouse key code. But I don't know what to use for Mouse Buttons.

I've tried WM_LBUTTONDOWN and MK_LBUTTON neither worked...

Any help would be much appreciated even if you are telling me to do it another way.

Share this post


Link to post
Share on other sites
Advertisement

I'm working on a little game engine, but I'm having trouble getting mouse input..

All I want right now is to determine whether the mouse is clicked or not because I have code for reading mouse coordinates already.

I figured I could use the same style of code as I did for my keyboard events but I cannot seem to find the right code for mouse events.

In a void I have the key events:

if (KEYDOWN(VK_ESCAPE))
Quit();

if (KEYDOWN(VK_RETURN))
{
mouseOn = true;
}

if (KEYDOWN(VK_SHIFT))
{
mouseOn = false;
}


That code works for disabling/enabling the mouse key code. But I don't know what to use for Mouse Buttons.

I've tried WM_LBUTTONDOWN and MK_LBUTTON neither worked...

Any help would be much appreciated even if you are telling me to do it another way.


First of all C++ doesn't actually handle input, an API will have to do that and in this case it is Windows! Now WM_LBUTTONDOWN is sent when the left mouse button is down over the window, more info can be found here: WM_LBUTTONDOWN. That is pretty useless though in that 'void', I assume you meant function, you need to use WndProc to process the windows message (WM), that link has an example of WM_MOUSEMOVE. I assume your program already has a WndProc so just find that and add what you need!

Share this post


Link to post
Share on other sites
Cool!

Yeah, I had seen in a couple examples that it was referencing message handling. I just didn't know if I could do it through this function. (sorry for calling it a void) I'm pretty bad at the actual terminology...

But thanks, I'll start working on that!

I had also seen that link before, that's where I had thought of using "mk_whatever".

I should probably handle everything through the LRESULT CALLBACK WindowProc sort of function right? I see that in a lot of examples and I figure that using a switch in there would be the best way to get every key press and mouse event at the same time?

Share this post


Link to post
Share on other sites

Cool!

Yeah, I had seen in a couple examples that it was referencing message handling. I just didn't know if I could do it through this function. (sorry for calling it a void) I'm pretty bad at the actual terminology...


Haha, no problem, it just makes it easier for everyone if everyone uses the same terminology for things!



But thanks, I'll start working on that!

I had also seen that link before, that's where I had thought of using "mk_whatever".

I should probably handle everything through the LRESULT CALLBACK WindowProc sort of function right? I see that in a lot of examples and I figure that using a switch in there would be the best way to get every key press and mouse event at the same time?


mk_* isn't a windows message (WM)! Yeah everything should essentially be in WndProc, you can use a switch statement if you want, it's what everyone else uses. Yep, that's how I do it.

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!