Skip to main content
GameDev.net gamedev.net
🔒 Locked

Catching mouseclicks

Started by Jesper T Aug 4, 2001 at 10:19 AM 1 replies 450+ views
Original Post
Jesper T
Jesper T
For keys i use e.g.: if(keys[''P'']) { thenDoThis(); } But how do I check if a mousebuttomhas been pressed ? ( could it be mouse[LEFT] or something ?? ) Thanks 4 ny help (This is proabably very simple, but if it isn''t, maybe someone can point me a tutorias or something ? )
Aribu
Aribu
If you''re programming C++ in Windows, and you don''t need a fast repeat rate for holding down the mouse button, the easiest way to do it is to use Windows Messages, and process it in your default message handler, (see SDK docs for info if you''re unfamiliar with Windows Messages).

There are a number of states that can be processed easily, such as:
WM_LBUTTONDBLCLK
WM_LBUTTONDOWN
WM_LBUTTONUP
etc.

To detect if the left mouse button was clicked, you would put something like the code below in your message handler:

case WM_LBUTTONDOWN:
{
//code or function call to be called when
//button is pushed

return(0);
} break;

If you need a fast repeat rate, however, and more instantaneous response, such as using the repeat in a game to fire a stream of fire, bullets, etc., you may wish to look into DirectX''s DirectInput, or the GetAsyncKeyState function (if not interested in DirectX.)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.