Archived

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

Sfpiano

Preventing an action from reoccuring while the mouse is down

Recommended Posts

When I right-click, one of a series of corresponding actions should be set off. The problem is that as long as the right button is down, that action will continue to go off. Is there a way to prevent this, other than having a bool variable for each action?

Share this post


Link to post
Share on other sites
I dont see how are you getting your right click as input, r button down message would seem most practical which i''d assume you arent using considering it is being constantly called, what''s going on here?

Share this post


Link to post
Share on other sites
All you have to do is have two booleans

rightclick
leftclick

When the mouse button is pushed down it sends a message to the WinProc (or whatever) that the button was pressed down. Holding it down doesn''t keep sending the message.

All you have to do is set rightclick to true when that message comes in and then

if(rightclick)
{
doaction();
rightclick=false;
}

rightclick won''t be set to true again until the user lets up on the mouse button and clicks it again.

Ben


[ IcarusIndie.com | recycledrussianbrides.com ]


Will post for food.

Share this post


Link to post
Share on other sites
I''m using DirectInput. I use a macro to determine mouse states :
#define MOUSEDOWN(name, key) ((name.rgbButtons[key] & 0x80) ? true : false). I don''t see how I could only use two booleans because I need to check multiple things when the mouse is down. Suppose action A gets called, and then sets the bool to false. But then I can''t call action B or C and vice versa.

Share this post


Link to post
Share on other sites
lol i made a topic just like kalvinb''s, and i re-read the question and relized what he was really asking and deleted it lol. Anyways I dont know direct input sorry I think one way or another the function is going to need something to tell it not to run, hence the need for the bools. if you really want to use one byte and you have 8 or less actions, you can use the bits

Share this post


Link to post
Share on other sites
If your method for getting mouse input doesn''t allow you to directly detect events (e.g. Allegro), than you do something like this in your update function:


static bool OldLMB = LMB;
static bool OldRMB = RMB;

if(LMB && !OldLMB)
{
//Respond to LMB pressed event

}

if(RMB && !OldRMB)
{
//Respond to RMB pressed event

}

OldLMB = LMB;
OldRMB = RMB;

Share this post


Link to post
Share on other sites
try these:

#define IS_SET(var, bit) ((var) & (bit))
#define SET_BIT(var, bit) ((var) |= (bit))
#define REMOVE_BIT(var, bit) ((var) &= ~(bit))
#define TOGGLE_BIT(var, bit) ((var) ^= (bit))


I find them very useful.

Share this post


Link to post
Share on other sites