Getting modifiers keys

Hi
I didnt figure out how to get a ‘modifier key down’ to work…
thats what im trying:

//…

//main program loop:

bool exitprogram=false;
while(exitprogram==false){

    ConfigDisplayGL();//updates the display each frame

        //handle events:
    while( SDL_PollEvent(&_event) ){//while theres svent:

        switch(_event.type){
            case SDL_KEYDOWN :{//if a key was pressed:
                switch(_event.key.keysym.sym){//what key?

                    case SDLK_ESCAPE: exitprogram = true; break;
                    case KMOD_SHIFT: kmodi    = true;        break;//a

shift modifier is down
case SDLK_r: kr = true; break;//r
= r + 0.1f;
case SDLK_g: kg = true; break;//g
= g + 0.1f;
case SDLK_b: kb = true; break;//b = b

  • 0.1f;

                  }//F switch what key?
              }
              break;
              case SDL_QUIT : exitprogram = true; break;//if pressed X on
    

the window
}//F switch _event.type

    }//F while theres event

        //updates modifications:
    if( kmodi == false ){                    //if no modifiers was

pressed

        if       ( kr == true ){ r = r + 0.1f;    kr = false; }
        else if( kg == true ){ g = g + 0.1f;    kg = false; }
        else if( kb == true ){ b = b + 0.1f;    kb = false; }

    }else if( kmodi == true ){                //if a shift modifier was

pressed

        if       ( kr == true ){ r = r - 0.1f;    kr = false; }
        else if( kg == true ){ g = g - 0.1f;    kg = false; }
        else if( kb == true ){ b = b - 0.1f;    kb = false; }
        kmodi = false;

    }//F if a modifier was or not pressed

    RenderTriangle( r, g, b);
    SDL_GL_SwapBuffers();//update back buffer to front buffer

}//F main program loop

//…

that is it, Im just getting MORE r , g and b values
I want that when shift + r or g or b is pressed the subtraction occurs, what
im missing?

The mod info is built into the event struct (SDL 1.2, right?). Look at
_event.key.keysym.mod for what modifiers were present when the key was
pressed.

Jonny DOn Wed, Feb 25, 2009 at 3:14 PM, Giuliano Pieta wrote:

Hi
I didnt figure out how to get a ‘modifier key down’ to work…
thats what im trying:

//…

//main program loop:

bool exitprogram=false;
while(exitprogram==false){

    ConfigDisplayGL();//updates the display each frame

        //handle events:
    while( SDL_PollEvent(&_event) ){//while theres svent:

        switch(_event.type){
            case SDL_KEYDOWN :{//if a key was pressed:
                switch(_event.key.keysym.sym){//what key?

                    case SDLK_ESCAPE: exitprogram = true; break;
                    case KMOD_SHIFT: kmodi    = true;        break;//a

shift modifier is down
case SDLK_r: kr = true; break;//r
= r + 0.1f;
case SDLK_g: kg = true; break;//g
= g + 0.1f;
case SDLK_b: kb = true; break;//b =
b + 0.1f;

                }//F switch what key?
            }
            break;
            case SDL_QUIT : exitprogram = true; break;//if pressed X on

the window
}//F switch _event.type

    }//F while theres event

        //updates modifications:
    if( kmodi == false ){                    //if no modifiers was

pressed

        if       ( kr == true ){ r = r + 0.1f;    kr = false; }
        else if( kg == true ){ g = g + 0.1f;    kg = false; }
        else if( kb == true ){ b = b + 0.1f;    kb = false; }

    }else if( kmodi == true ){                //if a shift modifier was

pressed

        if       ( kr == true ){ r = r - 0.1f;    kr = false; }
        else if( kg == true ){ g = g - 0.1f;    kg = false; }
        else if( kb == true ){ b = b - 0.1f;    kb = false; }
        kmodi = false;

    }//F if a modifier was or not pressed

    RenderTriangle( r, g, b);
    SDL_GL_SwapBuffers();//update back buffer to front buffer

}//F main program loop

//…

that is it, Im just getting MORE r , g and b values
I want that when shift + r or g or b is pressed the subtraction occurs,
what im missing?


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

Tanks, yeah I think is 1.2.13

I still dont get it to work
I tryied both things:

//…
switch(_event.type){
case SDL_KEYDOWN :{//if a key was pressed:

                switch(_event.key.keysym.sym){//what key?
                    case SDLK_ESCAPE: exitprogram = true; break;

                    case SDLK_r:    //r = r + 0.1f;
                        kr    = true;
                        if(_event.key.keysym.mod == KMOD_SHIFT ) kmodi =

true;
break;
case SDLK_g: //g = g + 0.1f;
kg = true;
if(_event.key.keysym.mod == KMOD_SHIFT ) kmodi =
true;

                        break;
                    case SDLK_b:    //b = b + 0.1f;
                        kb    = true;
                        if(_event.key.keysym.mod == KMOD_SHIFT ) kmodi =

true;

                        break;
                }//F switch what key?

//…

and :
//…
switch(_event.key.keysym.mod){
case KMOD_SHIFT:
kmodi=true;
switch(_event.key.keysym.sym){
case SDLK_r: kr = true; break;
case SDLK_g: kg = true; break;
case SDLK_b: kb = true; break;
}//F switch key sym
break;

                    case KMOD_NONE:
                        switch(_event.key.keysym.sym){
                            case SDLK_r: kr      = true; break;
                            case SDLK_g: kg     = true; break;
                            case SDLK_b: kb     = true; break;
                        }//F switch key sym
                    break;
                }//F switch key modifier

            }//F case key down
            break;

//…

The first keeped the same result( just more r g b values)
But with the second notthing happens, the program is not getting any key
mod…

2009/2/25 Jonathan Dearborn > The mod info is built into the event struct (SDL 1.2, right?). Look at

_event.key.keysym.mod for what modifiers were present when the key was
pressed.

Jonny D

On Wed, Feb 25, 2009 at 3:14 PM, Giuliano Pieta <@Giuliano_Pieta>wrote:

Hi
I didnt figure out how to get a ‘modifier key down’ to work…
thats what im trying:

//…

//main program loop:

bool exitprogram=false;
while(exitprogram==false){

    ConfigDisplayGL();//updates the display each frame

        //handle events:
    while( SDL_PollEvent(&_event) ){//while theres svent:

        switch(_event.type){
            case SDL_KEYDOWN :{//if a key was pressed:
                switch(_event.key.keysym.sym){//what key?

                    case SDLK_ESCAPE: exitprogram = true; break;
                    case KMOD_SHIFT: kmodi    = true;        break;//a

shift modifier is down
case SDLK_r: kr = true;
break;//r = r + 0.1f;
case SDLK_g: kg = true;
break;//g = g + 0.1f;
case SDLK_b: kb = true; break;//b =
b + 0.1f;

                }//F switch what key?
            }
            break;
            case SDL_QUIT : exitprogram = true; break;//if pressed X

on the window
}//F switch _event.type

    }//F while theres event

        //updates modifications:
    if( kmodi == false ){                    //if no modifiers was

pressed

        if       ( kr == true ){ r = r + 0.1f;    kr = false; }
        else if( kg == true ){ g = g + 0.1f;    kg = false; }
        else if( kb == true ){ b = b + 0.1f;    kb = false; }

    }else if( kmodi == true ){                //if a shift modifier

was pressed

        if       ( kr == true ){ r = r - 0.1f;    kr = false; }
        else if( kg == true ){ g = g - 0.1f;    kg = false; }
        else if( kb == true ){ b = b - 0.1f;    kb = false; }
        kmodi = false;

    }//F if a modifier was or not pressed

    RenderTriangle( r, g, b);
    SDL_GL_SwapBuffers();//update back buffer to front buffer

}//F main program loop

//…

that is it, Im just getting MORE r , g and b values
I want that when shift + r or g or b is pressed the subtraction occurs,
what im missing?


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

You’re looking for the SDL_GetModState section of the SDL documentation.
Try this:
case SDLK_r:
if(_event.key.keysym.mod & KMOD_SHIFT)
{
// Now you know that ‘r’ was pressed with shift
r = r - 0.1f;
}

Jonny DOn Wed, Feb 25, 2009 at 4:15 PM, Giuliano Pieta wrote:

Tanks, yeah I think is 1.2.13

I still dont get it to work
I tryied both things:

//…
switch(_event.type){
case SDL_KEYDOWN :{//if a key was pressed:

                switch(_event.key.keysym.sym){//what key?
                    case SDLK_ESCAPE: exitprogram = true; break;

                    case SDLK_r:    //r = r + 0.1f;
                        kr    = true;
                        if(_event.key.keysym.mod == KMOD_SHIFT ) kmodi

= true;
break;
case SDLK_g: //g = g + 0.1f;
kg = true;
if(_event.key.keysym.mod == KMOD_SHIFT ) kmodi
= true;

                        break;
                    case SDLK_b:    //b = b + 0.1f;
                        kb    = true;
                        if(_event.key.keysym.mod == KMOD_SHIFT ) kmodi

= true;

                        break;
                }//F switch what key?

//…

and :
//…
switch(_event.key.keysym.mod){
case KMOD_SHIFT:
kmodi=true;
switch(_event.key.keysym.sym){
case SDLK_r: kr = true; break;
case SDLK_g: kg = true; break;
case SDLK_b: kb = true; break;
}//F switch key sym
break;

                    case KMOD_NONE:
                        switch(_event.key.keysym.sym){
                            case SDLK_r: kr      = true; break;
                            case SDLK_g: kg     = true; break;
                            case SDLK_b: kb     = true; break;
                        }//F switch key sym
                    break;
                }//F switch key modifier

            }//F case key down
            break;

//…

The first keeped the same result( just more r g b values)
But with the second notthing happens, the program is not getting any key
mod…

2009/2/25 Jonathan Dearborn <@Jonathan_Dearborn>

The mod info is built into the event struct (SDL 1.2, right?). Look at

_event.key.keysym.mod for what modifiers were present when the key was
pressed.

Jonny D

On Wed, Feb 25, 2009 at 3:14 PM, Giuliano Pieta wrote:

Hi
I didnt figure out how to get a ‘modifier key down’ to work…
thats what im trying:

//…

//main program loop:

bool exitprogram=false;
while(exitprogram==false){

    ConfigDisplayGL();//updates the display each frame

        //handle events:
    while( SDL_PollEvent(&_event) ){//while theres svent:

        switch(_event.type){
            case SDL_KEYDOWN :{//if a key was pressed:
                switch(_event.key.keysym.sym){//what key?

                    case SDLK_ESCAPE: exitprogram = true; break;
                    case KMOD_SHIFT: kmodi    = true;

break;//a shift modifier is down
case SDLK_r: kr = true;
break;//r = r + 0.1f;
case SDLK_g: kg = true;
break;//g = g + 0.1f;
case SDLK_b: kb = true; break;//b
= b + 0.1f;

                }//F switch what key?
            }
            break;
            case SDL_QUIT : exitprogram = true; break;//if pressed X

on the window
}//F switch _event.type

    }//F while theres event

        //updates modifications:
    if( kmodi == false ){                    //if no modifiers was

pressed

        if       ( kr == true ){ r = r + 0.1f;    kr = false; }
        else if( kg == true ){ g = g + 0.1f;    kg = false; }
        else if( kb == true ){ b = b + 0.1f;    kb = false; }

    }else if( kmodi == true ){                //if a shift modifier

was pressed

        if       ( kr == true ){ r = r - 0.1f;    kr = false; }
        else if( kg == true ){ g = g - 0.1f;    kg = false; }
        else if( kb == true ){ b = b - 0.1f;    kb = false; }
        kmodi = false;

    }//F if a modifier was or not pressed

    RenderTriangle( r, g, b);
    SDL_GL_SwapBuffers();//update back buffer to front buffer

}//F main program loop

//…

that is it, Im just getting MORE r , g and b values
I want that when shift + r or g or b is pressed the subtraction occurs,
what im missing?


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

Tanks a lot, it works =D

2009/2/25 Jonathan Dearborn > You’re looking for the SDL_GetModState section of the SDL documentation.

Try this:
case SDLK_r:
if(_event.key.keysym.mod & KMOD_SHIFT)
{
// Now you know that ‘r’ was pressed with shift
r = r - 0.1f;
}

Jonny D

On Wed, Feb 25, 2009 at 4:15 PM, Giuliano Pieta <@Giuliano_Pieta>wrote:

Tanks, yeah I think is 1.2.13

I still dont get it to work
I tryied both things:

//…
switch(_event.type){
case SDL_KEYDOWN :{//if a key was pressed:

                switch(_event.key.keysym.sym){//what key?
                    case SDLK_ESCAPE: exitprogram = true; break;

                    case SDLK_r:    //r = r + 0.1f;
                        kr    = true;
                        if(_event.key.keysym.mod == KMOD_SHIFT ) kmodi

= true;
break;
case SDLK_g: //g = g + 0.1f;
kg = true;
if(_event.key.keysym.mod == KMOD_SHIFT ) kmodi
= true;

                        break;
                    case SDLK_b:    //b = b + 0.1f;
                        kb    = true;
                        if(_event.key.keysym.mod == KMOD_SHIFT ) kmodi

= true;

                        break;
                }//F switch what key?

//…

and :
//…
switch(_event.key.keysym.mod){
case KMOD_SHIFT:
kmodi=true;
switch(_event.key.keysym.sym){
case SDLK_r: kr = true; break;
case SDLK_g: kg = true; break;
case SDLK_b: kb = true; break;
}//F switch key sym
break;

                    case KMOD_NONE:
                        switch(_event.key.keysym.sym){
                            case SDLK_r: kr      = true; break;
                            case SDLK_g: kg     = true; break;
                            case SDLK_b: kb     = true; break;
                        }//F switch key sym
                    break;
                }//F switch key modifier

            }//F case key down
            break;

//…

The first keeped the same result( just more r g b values)
But with the second notthing happens, the program is not getting any key
mod…

2009/2/25 Jonathan Dearborn

The mod info is built into the event struct (SDL 1.2, right?). Look at

_event.key.keysym.mod for what modifiers were present when the key was
pressed.

Jonny D

On Wed, Feb 25, 2009 at 3:14 PM, Giuliano Pieta <@Giuliano_Pieta>wrote:

Hi
I didnt figure out how to get a ‘modifier key down’ to work…
thats what im trying:

//…

//main program loop:

bool exitprogram=false;
while(exitprogram==false){

    ConfigDisplayGL();//updates the display each frame

        //handle events:
    while( SDL_PollEvent(&_event) ){//while theres svent:

        switch(_event.type){
            case SDL_KEYDOWN :{//if a key was pressed:
                switch(_event.key.keysym.sym){//what key?

                    case SDLK_ESCAPE: exitprogram = true; break;
                    case KMOD_SHIFT: kmodi    = true;

break;//a shift modifier is down
case SDLK_r: kr = true;
break;//r = r + 0.1f;
case SDLK_g: kg = true;
break;//g = g + 0.1f;
case SDLK_b: kb = true; break;//b
= b + 0.1f;

                }//F switch what key?
            }
            break;
            case SDL_QUIT : exitprogram = true; break;//if pressed X

on the window
}//F switch _event.type

    }//F while theres event

        //updates modifications:
    if( kmodi == false ){                    //if no modifiers was

pressed

        if       ( kr == true ){ r = r + 0.1f;    kr = false; }
        else if( kg == true ){ g = g + 0.1f;    kg = false; }
        else if( kb == true ){ b = b + 0.1f;    kb = false; }

    }else if( kmodi == true ){                //if a shift modifier

was pressed

        if       ( kr == true ){ r = r - 0.1f;    kr = false; }
        else if( kg == true ){ g = g - 0.1f;    kg = false; }
        else if( kb == true ){ b = b - 0.1f;    kb = false; }
        kmodi = false;

    }//F if a modifier was or not pressed

    RenderTriangle( r, g, b);
    SDL_GL_SwapBuffers();//update back buffer to front buffer

}//F main program loop

//…

that is it, Im just getting MORE r , g and b values
I want that when shift + r or g or b is pressed the subtraction occurs,
what im missing?


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