Capture left and right clicks in SDL

Hey guys, i’ve been having some trouble while trying to capture both left
and right clicks in SDL, so far i looked at two websites that have
information about this and this are the two options i tried, with no
success:

  1. using the event structure, accesing the button structure, then the
    button member, which didnt actually work.
  2. using the SDL_GetKeyState function along with the macros
    SDL_BUTTON_LMASK and SDL_BUTTON_RMASK that return the corresponding bitmask.

… and none of this worked… Any ideas?

Sorry for the english, i might have had a few mistakes…

Have you created a window? I don’t think the mouse handler gets activated
if you don’t have a window setup.On Mon, Oct 22, 2012 at 3:44 PM, Hern?n Gurmendi wrote:

Hey guys, i’ve been having some trouble while trying to capture both left
and right clicks in SDL, so far i looked at two websites that have
information about this and this are the two options i tried, with no
success:

  1. using the event structure, accesing the button structure, then the
    button member, which didnt actually work.
  2. using the SDL_GetKeyState function along with the macros
    SDL_BUTTON_LMASK and SDL_BUTTON_RMASK that return the corresponding bitmask.

… and none of this worked… Any ideas?

Sorry for the english, i might have had a few mistakes…


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

What OS are you on? Typically, events are the way to go for such things:
if(event.button.button == SDL_BUTTON_LEFT)

else if(event.button.button == SDL_BUTTON_RIGHT)

But there’s also the state-based usage, which is useful sometimes
(specifically, I use it for when I want to respond to a key press/hold only
when a mouse button is held):
Uint8 mouse_state = SDL_GetMouseState(NULL, NULL);
if(mouse_state & SDL_BUTTON_LMASK)

else if(mouse_state & SDL_BUTTON_RMASK)

Jonny DOn Mon, Oct 22, 2012 at 3:46 PM, Alex Barry <alex.barry at gmail.com> wrote:

Have you created a window? I don’t think the mouse handler gets activated
if you don’t have a window setup.

On Mon, Oct 22, 2012 at 3:44 PM, Hern?n Gurmendi wrote:

Hey guys, i’ve been having some trouble while trying to capture both left
and right clicks in SDL, so far i looked at two websites that have
information about this and this are the two options i tried, with no
success:

  1. using the event structure, accesing the button structure, then the
    button member, which didnt actually work.
  2. using the SDL_GetKeyState function along with the macros
    SDL_BUTTON_LMASK and SDL_BUTTON_RMASK that return the corresponding bitmask.

… and none of this worked… Any ideas?

Sorry for the english, i might have had a few mistakes…


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

@Alex, yeah, i created a window and displayed some bitmaps. No problem
there so far, i even got to capture some basic mouse events like motion,
mousedown and mouseup with no problems, but i cant really get to handle the
left and right buttons down at the same time.

@Jonathan, im currently using windows to compile the code, but i could try
this at ubuntu, ill let you guys know in any case.

Thanks for the quick answers, any more feedback will be great!
Cheers!

2012/10/22 Jonathan Dearborn > What OS are you on? Typically, events are the way to go for such things:

if(event.button.button == SDL_BUTTON_LEFT)

else if(event.button.button == SDL_BUTTON_RIGHT)

But there’s also the state-based usage, which is useful sometimes
(specifically, I use it for when I want to respond to a key press/hold only
when a mouse button is held):
Uint8 mouse_state = SDL_GetMouseState(NULL, NULL);
if(mouse_state & SDL_BUTTON_LMASK)

else if(mouse_state & SDL_BUTTON_RMASK)

Jonny D

On Mon, Oct 22, 2012 at 3:46 PM, Alex Barry <alex.barry at gmail.com> wrote:

Have you created a window? I don’t think the mouse handler gets
activated if you don’t have a window setup.

On Mon, Oct 22, 2012 at 3:44 PM, Hern?n Gurmendi <@Hernan_Gurmendi>wrote:

Hey guys, i’ve been having some trouble while trying to capture both
left and right clicks in SDL, so far i looked at two websites that have
information about this and this are the two options i tried, with no
success:

  1. using the event structure, accesing the button structure, then the
    button member, which didnt actually work.
  2. using the SDL_GetKeyState function along with the macros
    SDL_BUTTON_LMASK and SDL_BUTTON_RMASK that return the corresponding bitmask.

… and none of this worked… Any ideas?

Sorry for the english, i might have had a few mistakes…


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

MouseDown and MouseUp should be your click events :)On Mon, Oct 22, 2012 at 4:53 PM, Hern?n Gurmendi wrote:

@Alex, yeah, i created a window and displayed some bitmaps. No problem
there so far, i even got to capture some basic mouse events like motion,
mousedown and mouseup with no problems, but i cant really get to handle the
left and right buttons down at the same time.

@Jonathan, im currently using windows to compile the code, but i could try
this at ubuntu, ill let you guys know in any case.

Thanks for the quick answers, any more feedback will be great!
Cheers!

2012/10/22 Jonathan Dearborn

What OS are you on? Typically, events are the way to go for such things:
if(event.button.button == SDL_BUTTON_LEFT)

else if(event.button.button == SDL_BUTTON_RIGHT)

But there’s also the state-based usage, which is useful sometimes
(specifically, I use it for when I want to respond to a key press/hold only
when a mouse button is held):
Uint8 mouse_state = SDL_GetMouseState(NULL, NULL);
if(mouse_state & SDL_BUTTON_LMASK)

else if(mouse_state & SDL_BUTTON_RMASK)

Jonny D

On Mon, Oct 22, 2012 at 3:46 PM, Alex Barry <@Alex_Barry> wrote:

Have you created a window? I don’t think the mouse handler gets
activated if you don’t have a window setup.

On Mon, Oct 22, 2012 at 3:44 PM, Hern?n Gurmendi wrote:

Hey guys, i’ve been having some trouble while trying to capture both
left and right clicks in SDL, so far i looked at two websites that have
information about this and this are the two options i tried, with no
success:

  1. using the event structure, accesing the button structure, then the
    button member, which didnt actually work.
  2. using the SDL_GetKeyState function along with the macros
    SDL_BUTTON_LMASK and SDL_BUTTON_RMASK that return the corresponding bitmask.

… and none of this worked… Any ideas?

Sorry for the english, i might have had a few mistakes…


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Oh, I think I see. You want simultaneous left and right click? SDL uses
only single events (with some key modifiers). This works using click
events:

Uint8 mouse_state = SDL_GetMouseState(NULL, NULL);
if((event.button.button == SDL_BUTTON_LEFT && mouse_state &
SDL_BUTTON_RMASK) || (event.button.button == SDL_BUTTON_RIGHT &&
mouse_state & SDL_BUTTON_LMASK))
{
// Both buttons are pressed. Do stuff.
}

That is one way. However, you have to store some timing info
(SDL_GetTicks()) if you require the buttons to be clicked simultaneously.
The above just fires once when both buttons are pressed, no matter how
long the first has been down.

Jonny DOn Mon, Oct 22, 2012 at 4:53 PM, Alex Barry <alex.barry at gmail.com> wrote:

MouseDown and MouseUp should be your click events :slight_smile:

On Mon, Oct 22, 2012 at 4:53 PM, Hern?n Gurmendi wrote:

@Alex, yeah, i created a window and displayed some bitmaps. No problem
there so far, i even got to capture some basic mouse events like motion,
mousedown and mouseup with no problems, but i cant really get to handle the
left and right buttons down at the same time.

@Jonathan, im currently using windows to compile the code, but i could
try this at ubuntu, ill let you guys know in any case.

Thanks for the quick answers, any more feedback will be great!
Cheers!

2012/10/22 Jonathan Dearborn <@Jonathan_Dearborn>

What OS are you on? Typically, events are the way to go for such things:
if(event.button.button == SDL_BUTTON_LEFT)

else if(event.button.button == SDL_BUTTON_RIGHT)

But there’s also the state-based usage, which is useful sometimes
(specifically, I use it for when I want to respond to a key press/hold only
when a mouse button is held):
Uint8 mouse_state = SDL_GetMouseState(NULL, NULL);
if(mouse_state & SDL_BUTTON_LMASK)

else if(mouse_state & SDL_BUTTON_RMASK)

Jonny D

On Mon, Oct 22, 2012 at 3:46 PM, Alex Barry <alex.barry at gmail.com>wrote:

Have you created a window? I don’t think the mouse handler gets
activated if you don’t have a window setup.

On Mon, Oct 22, 2012 at 3:44 PM, Hern?n Gurmendi wrote:

Hey guys, i’ve been having some trouble while trying to capture both
left and right clicks in SDL, so far i looked at two websites that have
information about this and this are the two options i tried, with no
success:

  1. using the event structure, accesing the button structure, then the
    button member, which didnt actually work.
  2. using the SDL_GetKeyState function along with the macros
    SDL_BUTTON_LMASK and SDL_BUTTON_RMASK that return the corresponding bitmask.

… and none of this worked… Any ideas?

Sorry for the english, i might have had a few mistakes…


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

@Jonathan yes, thats what i meant, sorry about the confusion, i guess i
didnt explain much about my problem :P. I tried that code you wrote and it
worked perfectly!

Thanks everyone for responding so quickly!
Have a nice day!

2012/10/22 Jonathan Dearborn > Oh, I think I see. You want simultaneous left and right click? SDL

uses only single events (with some key modifiers). This works using click
events:

Uint8 mouse_state = SDL_GetMouseState(NULL, NULL);
if((event.button.button == SDL_BUTTON_LEFT && mouse_state &
SDL_BUTTON_RMASK) || (event.button.button == SDL_BUTTON_RIGHT &&
mouse_state & SDL_BUTTON_LMASK))
{
// Both buttons are pressed. Do stuff.
}

That is one way. However, you have to store some timing info
(SDL_GetTicks()) if you require the buttons to be clicked simultaneously.
The above just fires once when both buttons are pressed, no matter how
long the first has been down.

Jonny D

On Mon, Oct 22, 2012 at 4:53 PM, Alex Barry <alex.barry at gmail.com> wrote:

MouseDown and MouseUp should be your click events :slight_smile:

On Mon, Oct 22, 2012 at 4:53 PM, Hern?n Gurmendi <@Hernan_Gurmendi>wrote:

@Alex, yeah, i created a window and displayed some bitmaps. No problem
there so far, i even got to capture some basic mouse events like motion,
mousedown and mouseup with no problems, but i cant really get to handle the
left and right buttons down at the same time.

@Jonathan, im currently using windows to compile the code, but i could
try this at ubuntu, ill let you guys know in any case.

Thanks for the quick answers, any more feedback will be great!
Cheers!

2012/10/22 Jonathan Dearborn

What OS are you on? Typically, events are the way to go for such
things:
if(event.button.button == SDL_BUTTON_LEFT)

else if(event.button.button == SDL_BUTTON_RIGHT)

But there’s also the state-based usage, which is useful sometimes
(specifically, I use it for when I want to respond to a key press/hold only
when a mouse button is held):
Uint8 mouse_state = SDL_GetMouseState(NULL, NULL);
if(mouse_state & SDL_BUTTON_LMASK)

else if(mouse_state & SDL_BUTTON_RMASK)

Jonny D

On Mon, Oct 22, 2012 at 3:46 PM, Alex Barry <alex.barry at gmail.com>wrote:

Have you created a window? I don’t think the mouse handler gets
activated if you don’t have a window setup.

On Mon, Oct 22, 2012 at 3:44 PM, Hern?n Gurmendi <@Hernan_Gurmendi>wrote:

Hey guys, i’ve been having some trouble while trying to capture both
left and right clicks in SDL, so far i looked at two websites that have
information about this and this are the two options i tried, with no
success:

  1. using the event structure, accesing the button structure, then the
    button member, which didnt actually work.
  2. using the SDL_GetKeyState function along with the macros
    SDL_BUTTON_LMASK and SDL_BUTTON_RMASK that return the corresponding bitmask.

… and none of this worked… Any ideas?

Sorry for the english, i might have had a few mistakes…


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org