what is the best way to detect mouse clicks in full screen mode?

Started by
3 comments, last by shurcool 22 years, 9 months ago
what is the best way to detect mouse clicks in full screen mode? please help, i need to know if the left mouse button is pressed down, and if the right mouse button is pressed down. to know that about middle mouse button would also be good. thanks, shurcool.
Advertisement
DirectInput is a nice way to get input in fullscreen mode,
take a look at the DX docs or read NeHe''s tutorial on it. If you want a class that wraps DI functionality up, let me know and i can send mine to you.

FatalXC
hi.
i have read both dx docs and nehe tuts, but they detect *keyboard* input (well, that''s what nehe tut is on), and i want the mouse clicks detection. i found some demos, but i don''t want to use dx, since i''m sure there''s another way to detect mouse clicks, and i want to keep the code portable. is there any way to detect mouse clicks without the mfc code, in full screen mode, and without using direct input? thanks for any help.
shurcool.
I''m not sure what you mean by portable, but I''ll give you the windows answer.

If you''re using DX or OpenGL or whatever in windows, you first need to create a window. As soon as you create the window (with the win32 API CreateWindow()) your code becomes dependant on win32 and therefore not portable. I don''t know of any portable solution to this. Portable meaning that you can use the same code on Windows and Linux, which is what I think portable means.

Anyways, back to windows, when you create the window you attach a function to that window (the function is usually called WindowProc) that recieves messages from the system. When a user left clicks on the window and WM_LBUTTONDOWN message is sent. WM_RBUTTONDOWN is for the right mouse button. You can guess what WM_MBUTTONDOWN does. Their''s also messages for when the user releases a mouse button.

What you do is trap these messages in the windowproc and have your program act accordingly. The position of the cursor is always returned when the mouse messages are sent.

For more info, look up WM_LBUTTONDOWN on msdn.microsoft.com/library
...keeping it simple...
I''m using GetAsyncKeyState() for detecting mouse clicks. In case you dont know, the virtual ley code for left mouse button is 0x01 and for right button it is 0x02. I do the check for button clicks with the code below (for the menu in my program)

static bool menuIsClicked(myButton abut)
{
if(GetAsyncKeyState(0x01))
{
if(menuCursorOnButton(abut)&&!bMouseDown)
{
sndPlaySound("/waves/mouseclick.wav", SND_ASYNC);
bMouseDown = true;
return true;
}
else
return false;
}
else
{
bMouseDown = false;
return false;
}
}

bMouseDown is a global boolean variable set to false at the beginning.

This topic is closed to new replies.

Advertisement