AltGr and other things

Hi!

First of all:
I am new to the list. Hi to everyone :slight_smile:

Now my questions:

I have this code in a program:

    SDL_Event event;
    int eventmask = SDL_EVENTMASK(SDL_KEYDOWN)
                                    | SDL_EVENTMASK(SDL_KEYUP)
                                    | SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN)
                                    | SDL_EVENTMASK(SDL_MOUSEBUTTONUP)
                                    | SDL_EVENTMASK(SDL_MOUSEMOTION)
                                    | SDL_EVENTMASK(SDL_JOYAXISMOTION)
                                    | SDL_EVENTMASK(SDL_JOYHATMOTION)
                                    | SDL_EVENTMASK(SDL_JOYBUTTONDOWN)
                                    | SDL_EVENTMASK(SDL_JOYBUTTONUP)
                                    | SDL_EVENTMASK(SDL_ACTIVEEVENT)

#ifdef SDL_GUI
| SDL_EVENTMASK(GUI_RETURN_INFO)
#endif
| SDL_EVENTMASK(SDL_QUIT);

    SDL_PumpEvents();
    while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, eventmask)) {
            int type = event.type;

            if (type == SDL_KEYDOWN || type == SDL_KEYUP) {
                    process_keyboard_event(event);
            }
            else if (type == SDL_MOUSEBUTTONDOWN || type == SDL_MOUSEBUTTONUP
            ...
            ...

static void process_keyboard_event(SDL_Event &event)
{
SDL_keysym keysym = event.key.keysym;
SDLKey sym = keysym.sym;
int state = SDL_GetModState(); // keysym.mod does not deliver single mod key presses for some reason

If I press AltGr now, I get FOUR events:

left ctrl down
right alt down
left ctrl up
right alt up

WHY? Why dont I get an event that would indicate, that AltGr was
pressed? In the variable “state” I ask the current ModState. Why am I
doing it with this function? Because keysym.mod != SDL_GetModState();

Again: Why?

And yet another question:
On my German keyboard I have a key with <,> and | on it. If I press
this key, then keysym.sym == 0!

And yet another: Why? :wink:

All this under Windows XP pro, SP 2.

What am I doing wrong? How can I change the behaviour? I am using
version 1.2.9

Cheers, Ingo =;->

Ingo Schmidt wrote:

Hi!

First of all:
I am new to the list. Hi to everyone :slight_smile:

Now my questions:

I have this code in a program:

   SDL_Event event;
   int eventmask = SDL_EVENTMASK(SDL_KEYDOWN)
                                   | SDL_EVENTMASK(SDL_KEYUP)
                                   | SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN)
                                   | SDL_EVENTMASK(SDL_MOUSEBUTTONUP)
                                   | SDL_EVENTMASK(SDL_MOUSEMOTION)
                                   | SDL_EVENTMASK(SDL_JOYAXISMOTION)
                                   | SDL_EVENTMASK(SDL_JOYHATMOTION)
                                   | SDL_EVENTMASK(SDL_JOYBUTTONDOWN)
                                   | SDL_EVENTMASK(SDL_JOYBUTTONUP)
                                   | SDL_EVENTMASK(SDL_ACTIVEEVENT)

#ifdef SDL_GUI
| SDL_EVENTMASK(GUI_RETURN_INFO)
#endif
| SDL_EVENTMASK(SDL_QUIT);

   SDL_PumpEvents();
   while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, eventmask)) {
           int type = event.type;

           if (type == SDL_KEYDOWN || type == SDL_KEYUP) {
                   process_keyboard_event(event);
           }
           else if (type == SDL_MOUSEBUTTONDOWN || type == SDL_MOUSEBUTTONUP
           ...
           ...

static void process_keyboard_event(SDL_Event &event)
{
SDL_keysym keysym = event.key.keysym;
SDLKey sym = keysym.sym;
int state = SDL_GetModState(); // keysym.mod does not deliver single mod key presses for some reason

Is this on a press AND release that you get the following four events?

If I press AltGr now, I get FOUR events:

left ctrl down
right alt down
left ctrl up
right alt up

If it is a press and release of those keys, then that is how it should
respond, given the code:

if (type == SDL_KEYDOWN || type == SDL_KEYUP) {

WHY? Why dont I get an event that would indicate, that AltGr was
pressed? In the variable “state” I ask the current ModState. Why am I
doing it with this function? Because keysym.mod != SDL_GetModState();

Again: Why?

And yet another question:
On my German keyboard I have a key with <,> and | on it. If I press
this key, then keysym.sym == 0!

And yet another: Why? :wink:

I’m sorry, I don’t know much about foreign keyboards and the way SDL
handles their keysyms, maybe someone else would know more about this
problem than I do.

All this under Windows XP pro, SP 2.

What am I doing wrong? How can I change the behaviour? I am using
version 1.2.9

Cheers, Ingo =;->


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

-Elden

Hi!

Is this on a press AND release that you get the following four events?

Yes, sorry, I wasnt precise.
I press AND release the AltGr key.

If it is a press and release of those keys, then that is how it should
respond, given the code:

The AltGr key IS supposed to send a “left ctrl” and then "right alt"
event??
Is it not supposed to send an AltGR event or something similar?

In the case of AltGr being pressed, I can actually make a workaround:
If I receive a “left ctrl down” event, I check with SDL_GetModState(),
if there was AltGr pressed, since SDL_GetModState() actually tells me
that.

But on AltGr release event, I am screwed. Because I receive the
following events on AltGr release:

“left ctrl released” and then “right alt released”. And in
SDL_GetModState() the bits for the AltGr key are no longer set.

So releasing AltGr results in an event, that is 100% identical to the
event “left control released”.

The only way to find out, that it was actually NOT a “left ctrl
release” event would be to check, if the next event was “right alt
released”. But this is quite a hack and I dont want to do it like
that.

I’m sorry, I don’t know much about foreign keyboards and the way SDL
handles their keysyms, maybe someone else would know more about this
problem than I do.

Where in the sources do I have to look, if I want to find out, how
libSDL looks for keyboard events? Where does libSDL get its info
from?

Cheers, Ingo =;->

Ingo Schmidt wrote:

Is this on a press AND release that you get the following four events?

Yes, sorry, I wasnt precise.
I press AND release the AltGr key.

If it is a press and release of those keys, then that is how it should
respond, given the code:

The AltGr key IS supposed to send a “left ctrl” and then "right alt"
event??
Is it not supposed to send an AltGR event or something similar?

Sorry, I wasn’t particularly sure if the AltGr was an abbreviation for
the CtlAlt combination on your keyboad or if it was a single key in and
of itself. What is the usual purpose for this key? That might clear
some things up for me. If it does function like the Ctl + Alt key
combinations on our keyboards here in the states, then it’s likely
that’s why you’re actually raising 4 events for one keys press and
release. I’ll do a little research and see how this key works at a
lower level.

In the case of AltGr being pressed, I can actually make a workaround:
If I receive a “left ctrl down” event, I check with SDL_GetModState(),
if there was AltGr pressed, since SDL_GetModState() actually tells me
that.

But on AltGr release event, I am screwed. Because I receive the
following events on AltGr release:

“left ctrl released” and then “right alt released”. And in
SDL_GetModState() the bits for the AltGr key are no longer set.

So releasing AltGr results in an event, that is 100% identical to the
event “left control released”.

The only way to find out, that it was actually NOT a “left ctrl
release” event would be to check, if the next event was “right alt
released”. But this is quite a hack and I dont want to do it like
that.

You could use SDL_GetModState() and check the state to see if on the
control key is active upon the alt being released. (I hope that made
sense, it’s a bit of a word maze.) If the control key state is not
active, then you can safely assume that since the alt key was release,
so was the control key.

I’m sorry, I don’t know much about foreign keyboards and the way SDL
handles their keysyms, maybe someone else would know more about this
problem than I do.

Where in the sources do I have to look, if I want to find out, how
libSDL looks for keyboard events? Where does libSDL get its info
from?

I would start with the SDL_keyboard.c file, and move to the other files
in the events subdirectory in the sources archive.
I’m very sorry there’s not more I could explain, but like I said
before…I have pretty much no experience with foreign keyboards or
their layouts. If we can determine how we can get it working properly,
and possibly work out a patch for 1.3.0 :slight_smile:
-Elden

AltGr is what the right Alt is called on some keyboard layouts where
it’s used as a second “shift” that produces an additionnal set of
extra characters when pressed (for example, on a french canadian
layout Shift+2 prints a quote while RightAlt+2 prints a @). Pressing
it should generate a right Alt event, nothing else.On 9/29/05, Elden Armbrust wrote:

Sorry, I wasn’t particularly sure if the AltGr was an abbreviation for
the CtlAlt combination on your keyboad or if it was a single key in and
of itself. What is the usual purpose for this key? That might clear
some things up for me. If it does function like the Ctl + Alt key
combinations on our keyboards here in the states, then it’s likely
that’s why you’re actually raising 4 events for one keys press and
release. I’ll do a little research and see how this key works at a
lower level.

Hi!

First of all:
I am new to the list. Hi to everyone :slight_smile:

Now my questions:

I have this code in a program:

    SDL_Event event;
    int eventmask = SDL_EVENTMASK(SDL_KEYDOWN)

                                    | SDL_EVENTMASK(SDL_KEYUP)
                                    | SDL_EVENTMASK(SDL_MOUSEBUTT
                                    |ONDOWN)
                                    | SDL_EVENTMASK(SDL_MOUSEBUTT
                                    |ONUP)
                                    | SDL_EVENTMASK(SDL_MOUSEMOTI
                                    |ON)
                                    | SDL_EVENTMASK(SDL_JOYAXISMO
                                    |TION)
                                    | SDL_EVENTMASK(SDL_JOYHATMOT
                                    |ION)
                                    | SDL_EVENTMASK(SDL_JOYBUTTON
                                    |DOWN)
                                    | SDL_EVENTMASK(SDL_JOYBUTTON
                                    |UP)
                                    | SDL_EVENTMASK(SDL_ACTIVEEVE
                                    |NT)

#ifdef SDL_GUI

                                    | SDL_EVENTMASK(GUI_RETURN_IN
                                    |FO)

#endif

                                    | SDL_EVENTMASK(SDL_QUIT);

    SDL_PumpEvents();
    while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, eventmask)) {
            int type = event.type;

            if (type == SDL_KEYDOWN || type == SDL_KEYUP) {
                    process_keyboard_event(event);
            }
            else if (type == SDL_MOUSEBUTTONDOWN || type ==

SDL_MOUSEBUTTONUP …

static void process_keyboard_event(SDL_Event &event)
{
SDL_keysym keysym = event.key.keysym;
SDLKey sym = keysym.sym;
int state = SDL_GetModState(); // keysym.mod does not deliver
single mod key presses for some reason …

How do you combine this information?
If you only press say right alt it should give you keysym of SDLK_RALT
It will not give you keysym.mod if you do not press any other key.

Could you send the combination code, because that is most likely doing
something wrong.On Thursday 29 September 2005 01:58, Ingo Schmidt wrote:

If I press AltGr now, I get FOUR events:

left ctrl down
right alt down
left ctrl up
right alt up

WHY? Why dont I get an event that would indicate, that AltGr was
pressed? In the variable “state” I ask the current ModState. Why am I
doing it with this function? Because keysym.mod != SDL_GetModState();

Again: Why?

And yet another question:
On my German keyboard I have a key with <,> and | on it. If I press
this key, then keysym.sym == 0!

And yet another: Why? :wink:

All this under Windows XP pro, SP 2.

What am I doing wrong? How can I change the behaviour? I am using
version 1.2.9

Cheers, Ingo =;->


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Hi!

How do you combine this information?

Not sure what you mean. I have extended my program:

static void process_keyboard_event(SDL_Event &event)
{
SDL_keysym keysym = event.key.keysym;
SDLKey sym = keysym.sym;
int state = SDL_GetModState();
D(bug(“scancode = %d ($%02x), keycode = ‘%s’ ($%02x),
state = $%02x, mod = $%02x”, keysym.scancode,
keysym.scancode, SDL_GetKeyName(sym), sym, state, keysym.mod));

I get the following 4 events when I press & release the AltGr key:

scancode = 29 ($1d), keycode = ‘left ctrl’ ($132), state = $1240, mod = $1000
scancode = 56 ($38), keycode = ‘right alt’ ($133), state = $1240, mod = $1040
scancode = 29 ($1d), keycode = ‘left ctrl’ ($132), state = $1000, mod = $1200
scancode = 56 ($38), keycode = ‘right alt’ ($133), state = $1000, mod = $1000

If I press & release left control, I get this:

scancode = 29 ($1d), keycode = ‘left ctrl’ ($132), state = $1040, mod = $1000
scancode = 29 ($1d), keycode = ‘left ctrl’ ($132), state = $1000, mod = $1000

And the key with <,> and | on it produces this:

scancode = 86 ($56), keycode = ‘unknown key’ ($00), state = $1000, mod = $1000
scancode = 86 ($56), keycode = ‘unknown key’ ($00), state = $1000, mod = $1000

I am a bit confused by all this. Or is everything correct and I am too
silly to see it?

The whole thing was compiled in a cygwin environment. cygwin1.dll is
needed to run the entire program. Is maybe that the problem?

Cheers, Ingo =;->

Hi!

How do you combine this information?

Not sure what you mean. I have extended my program:

static void process_keyboard_event(SDL_Event &event)
{
SDL_keysym keysym = event.key.keysym;
SDLKey sym = keysym.sym;
int state = SDL_GetModState();
D(bug(“scancode = %d ($%02x), keycode = ‘%s’ ($%02x),
state = $%02x, mod = $%02x”, keysym.scancode,
keysym.scancode, SDL_GetKeyName(sym), sym, state,
keysym.mod)); …

I get the following 4 events when I press & release the AltGr key:

scancode = 29 ($1d), keycode = ‘left ctrl’ ($132), state = $1240, mod
= $1000 scancode = 56 ($38), keycode = ‘right alt’ ($133), state =
$1240, mod = $1040 scancode = 29 ($1d), keycode = ‘left ctrl’ ($132),
state = $1000, mod = $1200 scancode = 56 ($38), keycode = ‘right alt’
($133), state = $1000, mod = $1000

Something wrong with the keyboard layout i would presume.
Can you make small test case, so that we can test this.

If I press & release left control, I get this:

scancode = 29 ($1d), keycode = ‘left ctrl’ ($132), state = $1040, mod
= $1000 scancode = 29 ($1d), keycode = ‘left ctrl’ ($132), state =
$1000, mod = $1000

And the key with <,> and | on it produces this:

scancode = 86 ($56), keycode = ‘unknown key’ ($00), state = $1000,
mod = $1000 scancode = 86 ($56), keycode = ‘unknown key’ ($00), state
= $1000, mod = $1000

I am a bit confused by all this. Or is everything correct and I am
too silly to see it?

The whole thing was compiled in a cygwin environment. cygwin1.dll is
needed to run the entire program. Is maybe that the problem?

Most likely I have to say.On Friday 30 September 2005 07:31, Ingo Schmidt wrote:

Cheers, Ingo =;->


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Ingo Schmidt wrote:

Hi!

First of all:
I am new to the list. Hi to everyone :slight_smile:

Now my questions:

I have this code in a program:

    SDL_Event event;
    int eventmask = SDL_EVENTMASK(SDL_KEYDOWN)
                                    | SDL_EVENTMASK(SDL_KEYUP)
                                    |

SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN)

                                    | SDL_EVENTMASK(SDL_MOUSEBUTTONUP)
                                    | SDL_EVENTMASK(SDL_MOUSEMOTION)
                                    | SDL_EVENTMASK(SDL_JOYAXISMOTION)
                                    | SDL_EVENTMASK(SDL_JOYHATMOTION)
                                    | SDL_EVENTMASK(SDL_JOYBUTTONDOWN)
                                    | SDL_EVENTMASK(SDL_JOYBUTTONUP)
                                    | SDL_EVENTMASK(SDL_ACTIVEEVENT)

#ifdef SDL_GUI
| SDL_EVENTMASK(GUI_RETURN_INFO)
#endif
| SDL_EVENTMASK(SDL_QUIT);

    SDL_PumpEvents();
    while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, eventmask)) {
            int type = event.type;

            if (type == SDL_KEYDOWN || type == SDL_KEYUP) {
                    process_keyboard_event(event);
            }
            else if (type == SDL_MOUSEBUTTONDOWN || type ==
            SDL_MOUSEBUTTONUP ...
            ...

static void process_keyboard_event(SDL_Event &event)
{
SDL_keysym keysym = event.key.keysym;
SDLKey sym = keysym.sym;
int state = SDL_GetModState(); // keysym.mod does not deliver
single mod key presses for some reason …

If I press AltGr now, I get FOUR events:

left ctrl down
right alt down
left ctrl up
right alt up

WHY? Why dont I get an event that would indicate, that AltGr was
pressed? In the variable “state” I ask the current ModState. Why am I
doing it with this function? Because keysym.mod != SDL_GetModState();

Again: Why?

And yet another question:
On my German keyboard I have a key with <,> and | on it. If I press
this key, then keysym.sym == 0!

And yet another: Why? :wink:

All this under Windows XP pro, SP 2.

What am I doing wrong? How can I change the behaviour? I am using
version 1.2.9

Cheers, Ingo =;->

I guess it’s due to the way Windows handles the AltGr key :

Too bad they have that broken way to do that.