PDA

View Full Version : Testing for Mouse Clicks



jeremyp
04-14-2001, 07:56 AM
I am trying to make a game with OpenGL in Windows. I need to know how to test for mouse clicks. I've spent hours going through header files and web pages already. Any help or tips would be greatly appreciated.

-Cat Slacker

Michael Steinberg
04-14-2001, 08:00 AM
You program win32 api? Then put your code into the WM_*BUTTONDOWN messages... GLUT suckz!!!! http://www.opengl.org/discussion_boards/ubb/smile.gif

jeremyp
04-14-2001, 08:10 AM
I am a newbie to OpenGL. I learned OpenGL from the tutorials on NeHe.gamedev.net. My knowledge is very limited. I don't know what Win32 API is. I just was wondering if anyone could tell me if there was a function call that tests for a left mouse click.

Michael Steinberg
04-14-2001, 08:13 AM
Okay nehe win32.
There's a function with a WNDPROC inside it and a huge switch-case statement.

Put a

case WM_LBUTTONDOWN:

there

Michael Steinberg
04-14-2001, 08:16 AM
That will test wether the user clicked the left mouse button down.

jeremyp
04-14-2001, 08:25 AM
I understand what you just said, but I'm not sure it can help me the way I want it to. I'm making an X-Wing fighter game. I put in the mouse coding from Lesson 23 from NeHe's site, and that works just fine. I can test for the x and y positions of the mouse. What I want to do is make a opening screen for my game. It'll have a new game section, high score, and exit buttons. I want to put a big if statement that tests if the mouse's x and y positions are in the corners of a button and if there is a left mouse click. If there is, it'll start a new game. Sounds simple, but I have no idea how to test for the mouse click. I wanted to use the keys array of keyboard buttons, but that's for the keyboard. I did find a MOUSEEVENTF_LEFTDOWN in Winuser.h, but I don't know how to use that. Hope that clarifies what I'm looking for.

Michael Steinberg
04-14-2001, 08:30 AM
Why can't you use that WM_LBUTTONDOWN in your code?

Michael Steinberg
04-14-2001, 08:31 AM
with that win32 message you'll also get the mouse position provided (and with WM_MOUSEMOVE etc.)

jeremyp
04-14-2001, 08:31 AM
never mind, I think I know how to use that now. I'll just make a bool veriable that I'll set to true in the case, for the mouse down, and I'll use another case WM_LBUTTONUP to set that variable to false. Then I'll use that bool variable in my if statements. Is that what I want to do??

Michael Steinberg
04-14-2001, 08:34 AM
Why don't you just test for a button-down? There can't be more than one buttondown in a click... Or if not then test for WM_LBUTTOUP.

jeremyp
04-14-2001, 08:37 AM
Thank you so much. That saved me from even more frustration and a really big head ache.

Michael Steinberg
04-14-2001, 08:40 AM
You're welcome.

dans
04-14-2001, 09:23 AM
int result = GetAsyncKeyState(VK_LBUTTON);

MSDN - If the function succeeds, the return value specifies whether the key was pressed since the last call to GetAsyncKeyState, and whether the key is currently up or down. If the most significant bit is set, the key is down, and if the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState. The return value is zero if a window in another thread or process currently has the keyboard focus.

[This message has been edited by dans (edited 04-14-2001).]