This topic is now archived and is closed to further replies.

Jesper T

Catching mouseclicks

Recommended Posts

Jesper T    322
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 ? )

Share this post

Link to post
Share on other sites
Aribu    122
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:

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

//code or function call to be called when
//button is pushed

} 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.)

Share this post

Link to post
Share on other sites