[SDL] Keyboard movement: Can't use two keys at once?

DARKGuy . dark.guy.2008 at gmail.com
Fri Sep 15 07:34:10 PDT 2006


Hehe, yup! that used to happen a lot when I used to play some DOS/Windows
games with my sister sharing the same keyboard. It beeped :P but thanks for
the code suggestion, I'll keep it for the case when I'll need to use it,
thanks! :D

On 9/15/06, Peter Mackay <mackay.pete+gmane at gmail.com> wrote:
>
> If a user presses two keys at once, you will get two "key down" messages
> (one for each key), so depending on how you're handling your events you
> can
> handle multiple keypresses there, or you can check the key state array.
>
> If you do that, you could do something like:
>
>     if (keystate[SDLK_A] && keystate[SDLK_B])
>     {
>         // Both keys are pressed.
>     }
>
> Note that due to keyboard hardware limitations, some key combinations (i.e
> .
> pressing several keys at once) will not register. Sometimes your PC will
> beep in this case. There's probably a good doc on the web somewhere about
> this, but I've just settled for never requiring several keys to be pressed
> at once.
>
> Most noticably, this problem shows up if you want to have 2 players share
> a
> keyboard for example. One player's keypresses can effectively block the
> other player's.
>
> Peter
>
> "DARKGuy ." <dark.guy.2008 at gmail.com> wrote in message
> news:9f8ddbb20609141058p184ecf66v97f612f463f1dfcf at mail.gmail.com...
> > Whoops! my bad then :( I think the only way is using IFs :P
> >
> > On 9/14/06, Peter Mulholland <darkmatter at freeuk.com> wrote:
> >>
> >> Hello DARKGuy,
> >>
> >> Thursday, September 14, 2006, 5:58:31 PM, you wrote:
> >>
> >> > I think it would be something like...
> >>
> >> > Uint8 *keystate = NULL;
> >> > switch (keystate = SDL_GetKeyState(NULL)){
> >> >     case SDLK_UP:
> >> >         move_up=true;
> >> >         break;
> >> >     case SDLK_DOWN:
> >> >         move_down=true;
> >> >         break;
> >> > }
> >>
> >> > I'm not at home, but that should do it I guess.
> >>
> >> No - the return value from SDL_GetKeyState() is a pointer. This would
> >> not do what you want.
> >>
> >> You cannot check an array using switch/case.
> >>
> >> --
> >> Best regards,
> >> Peter                            mailto:darkmatter at freeuk.com
> >>
> >>
> >> _______________________________________________
> >> SDL mailing list
> >> SDL at libsdl.org
> >> http://www.libsdl.org/mailman/listinfo/sdl
> >>
> >
>
>
>
> --------------------------------------------------------------------------------
>
>
> > _______________________________________________
> > SDL mailing list
> > SDL at libsdl.org
> > http://www.libsdl.org/mailman/listinfo/sdl
> >
>
>
>
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20060915/61bb7c50/attachment-0008.htm>


More information about the SDL mailing list