Sign in to follow this  
DavW

Oddly behaving SDL keyboard stuff

Recommended Posts

Some key combinations (up to 5 keys in some cases) work fine and all keys function properly, but other key combinations (as few as 3) lock up and prevent further keypresses until they are released. I am using the following code to check keyboard events:
int key[323];
void inputinit() {
    int i;
    for (i=0;i<323;i++) {
        key[i]=0;
    }
}
void pollkeyboard() {
    SDL_Event event;
    while(SDL_PollEvent(&event)) {          //whilst there are events in the queue
        switch(event.type) {       
            case SDL_KEYDOWN:               //check for keydown
                key[event.key.keysym.sym]=1;
                break;
            case SDL_KEYUP:
                key[event.key.keysym.sym]=0;
                break;
            case SDL_QUIT:
                running=0;
        }
    }
}

Ideas anyone?

Share this post


Link to post
Share on other sites
That's not a SDL problem, that's a keyboard problem. Keyboards are not designed for multiple keys being held down (other than the shift/alt/ctrl/etc keys), so they use a wiring system that doesn't allow all key combinations to be used
(it saves on wires, and makes the design simpler)

All I can say is "Don't use that key combo in your game" :(

Share this post


Link to post
Share on other sites
So how do so many games manage to have 2 players on a keyboard? I've tried changing the mappings loads of times but keys are still locking each other out. It's very bizarre. Liero, for example, uses 7 keys per player and 2 on a keyboard with no apparent lockouts at all, but when I use mapping as similar as I can to Liero's, I still see problems.

Share this post


Link to post
Share on other sites
Typically, two-player-one-keyboard games don't use 3+ key combinations per player. A standard PC keyboard typically only allows for 4 or 5 simultaneous key presses.

As to some key combinations locking out the keyboard, it could be that those key combinations are platform specific. For example, on unix with the terminial in "cooked" mode, Ctrl-S will lock out keyboard input until Ctrl-Q (i think) is pressed.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this