Problems with key events

Hi,

I have figured out some problems with key events. (Tested on SDL-1.2.11
and SDL-1.2.13 on Linux.)

I have written a very simple test-application, basically this:

int main() {
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
SDL_SetVideoMode(100, 100, 32, 0);
EventLoop();
SDL_Quit();
}

And in EventLoop() I just give information about all pressed and
released keys (I catch the SDL_KEYUP and SDL_KEYDOWN).

I did now the following:

  • pressed SDLK_TOP
  • pressed SDLK_LEFT
  • pressed SDLK_RIGHT
  • released SDLK_TOP
  • released SDLK_LEFT
  • released SDLK_RIGHT

I get this output (I have added some comments):______________
type: 2
state: 1
sym: 273 // TOP down
unicode: 0
mod: 0
scancode: 98


type: 2
state: 1
sym: 276 // LEFT down
unicode: 0
mod: 0
scancode: 100


RIGHT key is not recognised!


type: 2
state: 1
sym: 279 // wrong! (released TOP, it’s also not RIGHT=275)
unicode: 0
mod: 0
scancode: 103 // wrong!


type: 3
state: 0
sym: 276 // LEFT up
unicode: 0
mod: 0
scancode: 100


type: 3
state: 0
sym: 279 // wrong! (released RIGHT)
unicode: 0
mod: 0
scancode: 103


type: 3
state: 0
sym: 273 // LEFT? (app lost focus)
unicode: 0
mod: 0
scancode: 0

I can reproduce similar problems when I press the keys in another order.
Though it seems to work correct if I use keys A-Z.

I figured this problem out in a game where keys got recognised as
staying pressed while they are not (it results that the player for
example just keeps going left). I use SDL_GetKeyState() there.

Does somebody know this problem? Or does somebody have some hints why
this could happen?

And possible workarounds? In this demo app, it seems that loosing focus
try to fix something but in my game it doesn’t change anything (the
players keeps running). I even can keep multiple keys “pressed” (for
example left + up; if I press down then, the cursor keeps always going
up after and the players keeps running left).

I have also tested this on the same machine but under MacOSX and the
problem does not occur there (I am also using a SDL >=1.2.11 there).

Greetings,
Albert

This is a well known problem with keyboards. Keyboards normally only
recognize the first 2 or 3 keys that are pressed. The limitations depend on
the keyboard. It has nothing to do with SDL.

Bob PendletonOn 2/14/08, Albert Zeyer <albert.zeyer at rwth-aachen.de> wrote:

Hi,

I have figured out some problems with key events. (Tested on SDL-1.2.11
and SDL-1.2.13 on Linux.)

I have written a very simple test-application, basically this:

int main() {
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
SDL_SetVideoMode(100, 100, 32, 0);
EventLoop();
SDL_Quit();
}

And in EventLoop() I just give information about all pressed and
released keys (I catch the SDL_KEYUP and SDL_KEYDOWN).

I did now the following:

  • pressed SDLK_TOP
  • pressed SDLK_LEFT
  • pressed SDLK_RIGHT
  • released SDLK_TOP
  • released SDLK_LEFT
  • released SDLK_RIGHT

I get this output (I have added some comments):


type: 2
state: 1
sym: 273 // TOP down
unicode: 0
mod: 0
scancode: 98


type: 2
state: 1
sym: 276 // LEFT down
unicode: 0
mod: 0
scancode: 100


RIGHT key is not recognised!


type: 2
state: 1
sym: 279 // wrong! (released TOP, it’s also not RIGHT=275)
unicode: 0
mod: 0
scancode: 103 // wrong!


type: 3
state: 0
sym: 276 // LEFT up
unicode: 0
mod: 0
scancode: 100


type: 3
state: 0
sym: 279 // wrong! (released RIGHT)
unicode: 0
mod: 0
scancode: 103


type: 3
state: 0
sym: 273 // LEFT? (app lost focus)
unicode: 0
mod: 0
scancode: 0

I can reproduce similar problems when I press the keys in another order.
Though it seems to work correct if I use keys A-Z.

I figured this problem out in a game where keys got recognised as
staying pressed while they are not (it results that the player for
example just keeps going left). I use SDL_GetKeyState() there.

Does somebody know this problem? Or does somebody have some hints why
this could happen?

And possible workarounds? In this demo app, it seems that loosing focus
try to fix something but in my game it doesn’t change anything (the
players keeps running). I even can keep multiple keys “pressed” (for
example left + up; if I press down then, the cursor keeps always going
up after and the players keeps running left).

I have also tested this on the same machine but under MacOSX and the
problem does not occur there (I am also using a SDL >=1.2.11 there).

Greetings,
Albert


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

It has. Or at least it is software related. As I said, under MacOSX I
don’t have the problem. (MacOSX on the same machine!)Am Donnerstag, den 14.02.2008, 07:38 -0600 schrieb Bob Pendleton:

This is a well known problem with keyboards. Keyboards normally only
recognize the first 2 or 3 keys that are pressed. The limitations
depend on the keyboard. It has nothing to do with SDL.

Bob Pendleton

On 2/14/08, Albert Zeyer <@Albert_Zeyer> wrote:
Hi,

    I have figured out some problems with key events. (Tested on
    SDL-1.2.11
    and SDL-1.2.13 on Linux.)
    
    I have written a very simple test-application, basically this:
    
    int main() {
    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
    SDL_SetVideoMode(100, 100, 32, 0);
    EventLoop();
    SDL_Quit();
    }
    
    And in EventLoop() I just give information about all pressed
    and
    released keys (I catch the SDL_KEYUP and SDL_KEYDOWN).
    
    I did now the following:
    - pressed SDLK_TOP
    - pressed SDLK_LEFT
    - pressed SDLK_RIGHT
    - released SDLK_TOP
    - released SDLK_LEFT
    - released SDLK_RIGHT
    
    I get this output (I have added some comments):
    
    ______________
    type: 2
    state: 1
    sym: 273 // TOP down
    unicode: 0
    mod: 0
    scancode: 98
    ______________
    type: 2
    state: 1
    sym: 276 // LEFT down
    unicode: 0
    mod: 0
    scancode: 100
    ______________
    RIGHT key is not recognised!
    ______________
    type: 2
    state: 1
    sym: 279 // wrong! (released TOP, it's also not RIGHT=275)
    unicode: 0
    mod: 0
    scancode: 103 // wrong!
    ______________
    type: 3
    state: 0
    sym: 276 // LEFT up
    unicode: 0
    mod: 0
    scancode: 100
    ______________
    type: 3
    state: 0
    sym: 279 // wrong! (released RIGHT)
    unicode: 0
    mod: 0
    scancode: 103
    ______________
    type: 3
    state: 0
    sym: 273 // LEFT? (app lost focus)
    unicode: 0
    mod: 0
    scancode: 0
    
    
    I can reproduce similar problems when I press the keys in
    another order.
    Though it seems to work correct if I use keys A-Z.
    
    I figured this problem out in a game where keys got recognised
    as
    staying pressed while they are not (it results that the player
    for
    example just keeps going left). I use SDL_GetKeyState() there.
    
    Does somebody know this problem? Or does somebody have some
    hints why
    this could happen?
    
    And possible workarounds? In this demo app, it seems that
    loosing focus
    try to fix something but in my game it doesn't change anything
    (the
    players keeps running). I even can keep multiple keys
    "pressed" (for
    example left + up; if I press down then, the cursor keeps
    always going
    up after and the players keeps running left).
    
    I have also tested this on the same machine but under MacOSX
    and the
    problem does not occur there (I am also using a SDL >=1.2.11
    there).
    
    Greetings,
    Albert
    
    
    _______________________________________________
    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

It has. Or at least it is software related. As I said, under MacOSX I
don’t have the problem. (MacOSX on the same machine!)

Oh, well now that is interesting. So, what OS are you having the trouble
with and how are you running it on a Mac? Are you running it natively or in
a VM? Was the second OS officially released for the Mac hardware or did you
just get it to run?

There are a lot of layers between the hardware and SDL. Anyone of them can
cause the kind of problem you are seeing.

Bob PendletonOn 2/14/08, Albert Zeyer <albert.zeyer at rwth-aachen.de> wrote:

Am Donnerstag, den 14.02.2008, 07:38 -0600 schrieb Bob Pendleton:

This is a well known problem with keyboards. Keyboards normally only
recognize the first 2 or 3 keys that are pressed. The limitations
depend on the keyboard. It has nothing to do with SDL.

Bob Pendleton

On 2/14/08, Albert Zeyer <albert.zeyer at rwth-aachen.de> wrote:
Hi,

    I have figured out some problems with key events. (Tested on
    SDL-1.2.11
    and SDL-1.2.13 on Linux.)

    I have written a very simple test-application, basically this:

    int main() {
    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
    SDL_SetVideoMode(100, 100, 32, 0);
    EventLoop();
    SDL_Quit();
    }

    And in EventLoop() I just give information about all pressed
    and
    released keys (I catch the SDL_KEYUP and SDL_KEYDOWN).

    I did now the following:
    - pressed SDLK_TOP
    - pressed SDLK_LEFT
    - pressed SDLK_RIGHT
    - released SDLK_TOP
    - released SDLK_LEFT
    - released SDLK_RIGHT

    I get this output (I have added some comments):

    ______________
    type: 2
    state: 1
    sym: 273 // TOP down
    unicode: 0
    mod: 0
    scancode: 98
    ______________
    type: 2
    state: 1
    sym: 276 // LEFT down
    unicode: 0
    mod: 0
    scancode: 100
    ______________
    RIGHT key is not recognised!
    ______________
    type: 2
    state: 1
    sym: 279 // wrong! (released TOP, it's also not RIGHT=275)
    unicode: 0
    mod: 0
    scancode: 103 // wrong!
    ______________
    type: 3
    state: 0
    sym: 276 // LEFT up
    unicode: 0
    mod: 0
    scancode: 100
    ______________
    type: 3
    state: 0
    sym: 279 // wrong! (released RIGHT)
    unicode: 0
    mod: 0
    scancode: 103
    ______________
    type: 3
    state: 0
    sym: 273 // LEFT? (app lost focus)
    unicode: 0
    mod: 0
    scancode: 0


    I can reproduce similar problems when I press the keys in
    another order.
    Though it seems to work correct if I use keys A-Z.

    I figured this problem out in a game where keys got recognised
    as
    staying pressed while they are not (it results that the player
    for
    example just keeps going left). I use SDL_GetKeyState() there.

    Does somebody know this problem? Or does somebody have some
    hints why
    this could happen?

    And possible workarounds? In this demo app, it seems that
    loosing focus
    try to fix something but in my game it doesn't change anything
    (the
    players keeps running). I even can keep multiple keys
    "pressed" (for
    example left + up; if I press down then, the cursor keeps
    always going
    up after and the players keeps running left).

    I have also tested this on the same machine but under MacOSX
    and the
    problem does not occur there (I am also using a SDL >=1.2.11
    there).

    Greetings,
    Albert


    _______________________________________________
    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

    It has. Or at least it is software related. As I said, under
    MacOSX I
    don't have the problem. (MacOSX on the same machine!)

Oh, well now that is interesting. So, what OS are you having the
trouble with and how are you running it on a Mac? Are you running it
natively or in a VM? Was the second OS officially released for the Mac
hardware or did you just get it to run?

I have a MacBook with both MacOSX and Linux natively installed.

There are a lot of layers between the hardware and SDL. Anyone of them
can cause the kind of problem you are seeing.

I have tried the xev application on Linux to watch the X11-events. Here
I have the same problem and almost the same data as with the demon
application in SDL.

I have compiled also the evbug module for debugging on Linux. It’s a
module which logs every single event.

My keyboard is internally connected on the USB-bus. The debug-data I got
from evbug seems to be the same as from SDL / X11 (but lot more
verbose). I also got different keyups if I press multiple keys here.

So it’s probably not SDL related. It seems to be a problem with the
Linux kernel, probably with its USB-keyboard driver. Probably MacOSX has
own drivers here. Or it’s already broken for a long time in the Linux
kernel as I have similar problems on some other machines (though I have
only tested Linux there, nothing else; but I also thought before that
it’s just a hardware restriction of keyboards).Am Donnerstag, den 14.02.2008, 10:30 -0600 schrieb Bob Pendleton:

On 2/14/08, Albert Zeyer <@Albert_Zeyer> wrote:

    It has. Or at least it is software related. As I said, under
    MacOSX I
    don't have the problem. (MacOSX on the same machine!)

Oh, well now that is interesting. So, what OS are you having the
trouble with and how are you running it on a Mac? Are you running it
natively or in a VM? Was the second OS officially released for the Mac
hardware or did you just get it to run?

I have a MacBook with both MacOSX and Linux natively installed.

There are a lot of layers between the hardware and SDL. Anyone of them
can cause the kind of problem you are seeing.

I have tried the xev application on Linux to watch the X11-events. Here
I have the same problem and almost the same data as with the demon
application in SDL.

I have compiled also the evbug module for debugging on Linux. It’s a
module which logs every single event.

My keyboard is internally connected on the USB-bus. The debug-data I got
from evbug seems to be the same as from SDL / X11 (but lot more
verbose). I also got different keyups if I press multiple keys here.

So it’s probably not SDL related. It seems to be a problem with the
Linux kernel, probably with its USB-keyboard driver. Probably MacOSX has
own drivers here. Or it’s already broken for a long time in the Linux
kernel as I have similar problems on some other machines (though I have
only tested Linux there, nothing else; but I also thought before that
it’s just a hardware restriction of keyboards).

It may be that Mac OS is initializing the keyboard in a different mode than
Linux is. That could cause the keyboard to emulate the behavior of a PS/2
keyboard. Emulating it so well that it emulates the bugs.

Bob PendletonOn 2/14/08, Albert Zeyer <albert.zeyer at rwth-aachen.de> wrote:

Am Donnerstag, den 14.02.2008, 10:30 -0600 schrieb Bob Pendleton:

On 2/14/08, Albert Zeyer <albert.zeyer at rwth-aachen.de> wrote:


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