Keyboard event

Hello,

how can I easily (one line, if possible) make the following test :

a shift key (left or right) is pressed, OR Capslock is locked, but not both.

thanks.

ps : I don’t want other keys to interfere with the results (such as num lock for instance).

is the question about how to make the IF statement, or how to get the actual
modifiers?

You can always track state of num lock/caps lock and include that in the IF
statement.

JohnOn Thu, May 6, 2010 at 3:24 AM, Lilly wrote:

ps : I don’t want other keys to interfere with the results (such as num
lock for instance).


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

both, I guess. I would just like a statement that works.
I’ve tried this, but it doesn’t work :
if (((event.key.keysym.mod & KMOD_SHIFT) & SDLK_CAPSLOCK) == (KMOD_SHIFT & SDLK_CAPSLOCK))

It doesn’t look right that you’re mixing KMOD and SDLK with only
event.key.keysym.mod.
Try something like:
if((event.key.keysym.mod & (KMOD_SHIFT | KMOD_CAPS)) == KMOD_SHIFT
|| (event.key.keysym.mod & (KMOD_SHIFT | KMOD_CAPS)) == KMOD_CAPS)

Jonny DOn Thu, May 6, 2010 at 8:24 AM, Lilly wrote:

both, I guess. I would just like a statement that works.
I’ve tried this, but it doesn’t work :
if (((event.key.keysym.mod & KMOD_SHIFT) & SDLK_CAPSLOCK) == (KMOD_SHIFT &
SDLK_CAPSLOCK))


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

SDLK_CAPSLOCK is not bitwise, it’s an enum that is 12D in hex. Therefore

KMOD_SHIFT & SDLK_CAPSLOCK evaluates to 1.

Hence your statement is equivalent to
if (event.key.keysym.mod & KMOD_SHIFT == 1).

Somehow I doubt that’s what you wanted.

HTH,
JeffOn Thursday 06 May 2010 08:24, Lilly wrote:

both, I guess. I would just like a statement that works.
I’ve tried this, but it doesn’t work :
if (((event.key.keysym.mod & KMOD_SHIFT) & SDLK_CAPSLOCK) == (KMOD_SHIFT &
SDLK_CAPSLOCK))

Try SDL_GetKeyState() ( http://www.libsdl.org/cgi/docwiki.cgi/SDL_GetKeyState ).On 5 May 2010 01:38, Lilly wrote:

Hello,

how can I easily (one line, if possible) make the following test :

a shift key (left or right) is pressed, OR Capslock is locked, but not both.

Jonny D, thanks for trying, but your proposition doesn’t work when shift is pressed.

Jeff Post, what do you suggest to make my if statement then ?

make that SDL_GetModState():

int mod = SDL_GetModState(); // or use event.key.keysym.mod
if (((mod & KMOD_SHIFT) != 0) ^ ((mod & KMOD_CAPS) != 0)) {
// do stuff…
}On 6 May 2010 13:00, Kenneth Bull <@Kenneth_Bull> wrote:

Try SDL_GetKeyState() ( http://www.libsdl.org/cgi/docwiki.cgi/SDL_GetKeyState ).

Okay, then it’s a trivial change. Have you studied C bitwise operators?
You should be able to use Ken’s expression in your test anyhow. I like it
better.

Jonny DOn Thu, May 6, 2010 at 10:00 AM, Lilly wrote:

Jonny D, thanks for trying, but your proposition doesn’t work when shift
is pressed.

Jeff Post, what do you suggest to make my if statement then ?


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

thanks, problem solved.