• 12
• 10
• 10
• 13
• 10

# Checking for Mouse Input? (C++)

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

## 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 on other sites

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 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 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 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!