Left and Right Mouse Button Event

I want to catch the left and right button event at the same time.

By SDL_MOUSEBUTTONDOWN event type, I can’t catch the event.

My Code :

case SDL_MOUSEBUTTONDOWN:
if (event->button.button == (SDL_BUTTON_LEFT | SDL_BUTTON_RIGHT)) {
…// here
}

But, If there are some time intervals between left click and right click, I
can catch it.

How can I get the left and right click event ?

Hi,On Mon, 19 Feb 2001, you wrote:

I want to catch the left and right button event at the same time.
By SDL_MOUSEBUTTONDOWN event type, I can’t catch the event.
My Code :

case SDL_MOUSEBUTTONDOWN:
if (event->button.button == (SDL_BUTTON_LEFT | SDL_BUTTON_RIGHT)) {
…// here
}

But, If there are some time intervals between left click and right click, I
can catch it.
How can I get the left and right click event ?

Just using some boolean flags:

// where you define variables for mouse events
bool leftB, rightB;

// init mouse button flags
leftB=rightB=false;

// in your main event loop (following the way you handle mouse buttons events)
case SDL_MOUSEBUTTONDOWN:
leftB=(event->button.down==SDL_BUTTON_LEFT);
rightB(event->button.down==SDL_BUTTON_RIGHT);

if (leftB && rightB)
{
// here both buttons are pressed
}
break;
case SDL_MOUSE_BUTTONUP:
leftB=(event->button.up==SDL_BUTTON_LEFT);
rightB(event->button.up==SDL_BUTTON_RIGHT);

break;

or

// depending on the way your application has to behave on button pressure,
// this way can be proper or sad (depending on the number of buttons you
// allow to use, and of sequences of releases and pressions of buttons.
case SDL_MOUSEBUTTONDOWN:
mouseButtons=SDL_GetMouseState(mouseX, mouseY);
if ((mouseButtons&(SDL_BUTTON(1)&(SDL_BUTTON(2))))
{

}
break;

or

you have to press both buttons simultaneously :)))

Of course, raising your trigger code if both buttons WERE pressed and ARE
NOW released, will lead to a lil’ bit more complex game with flags or more
generally with mouse buttons event handling (still simple). They are many ways
to do what you want, you just have to use properly the SDL_MouseButtonEvent
struct or the directly read the mouse state. Don’t forget to check the previous
mouse state else you will get strange behaviour when using the 3 or 5 buttons
of a mouse. If you still press buttons 1 & 2, the event SDL_MOUSEBUTTONDOWN will
be raised when 5th button is pressed, and your code executed, but it is not a
NEW 1&2 button press - think also of managing the release status of the buttons
you want to manage as “pressed”.

Cheers,

wwp

Are you using X11? If so, then you probably have Emulate3Buttons or
whatever enabled. So pressing the left and right button produces a
middle button event. Not a SDL problem, check your XF86Config.On Mon, Feb 19, 2001 at 06:25:27AM -0800, Jiho Choi wrote:

I want to catch the left and right button event at the same time.

By SDL_MOUSEBUTTONDOWN event type, I can’t catch the event.

My Code :

case SDL_MOUSEBUTTONDOWN:
if (event->button.button == (SDL_BUTTON_LEFT | SDL_BUTTON_RIGHT)) {
…// here
}

But, If there are some time intervals between left click and right click, I
can catch it.

How can I get the left and right click event ?


Martin

Bother!: a Pooh poo.

I want to catch the left and right button event at the same time.

No Problem so far :slight_smile:

By SDL_MOUSEBUTTONDOWN event type, I can’t catch the event.

My Code :
case SDL_MOUSEBUTTONDOWN:
if (event->button.button == (SDL_BUTTON_LEFT | SDL_BUTTON_RIGHT)) {
…// here
}

But, If there are some time intervals between left click and right click,
I
can catch it.

How can I get the left and right click event ?

Yep, because you have to think of the SDL Event Queue as a list, that
collects one event after another. So if you catch the events with
SDL_PollEvent (&event); you only will get the first event of the list. But
if you press the left and right mouse button, there will be two single
events passed to the queue (i am not sure, what happens, if there is no time
intervall between, but i guess it would be the same):

event[0] = secound mouse button pressed was put in queue (i.e. button(1)
left)
event[1] = first mouse button pressed in queue (i.e.button(2) right).

you have two possiblilities:

1.) Write a structure, that monitors the mouse itself and define it as a
global variable (you will need that for double clicks and drag-and-drop and
stuff), or:

2.) dont use (event->button.button),
but use :

case SDL_MOUSEBUTTONDOWN:
if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1)&SDL_BUTTON(3)) {
//now you know, that both are pressed :slight_smile:
}

hope this helped and is correct,

greetings

sascha