Multiple Keys down in SDL

Posts: 21
Joined: 2008.11
Post: #1

I am working on basic input functions in SDL and have run into a problem. I want user's to be able to press ALT - ENTER and have the program go into full screen. I have started to write the function but can not get it to recognize when I press the second key. Heres what I have:

void checkInput()
    if (SDL_PollEvent(&input))
        if (input.type == SDL_KEYDOWN)
            SDLKey keyPressed = input.key.keysym.sym;
            switch (keyPressed)
                case SDLK_RALT:
                    printf("Right ALT key pressed.\n");

I tried putting another switch after the ALT key is down but it doesn't see it. What do I need to do here to get this to work?
Quote this message in a reply
Posts: 1,563
Joined: 2003.10
Post: #2
You can rely on your user input API to tell you when individual keys are pressed and released, but beyond that, you'll need to keep track of their state yourself. Keep boolean variables for each key you care about, set them to true when the key is pressed, set them to false when they're released, and take action based on the state of your booleans.
Quote this message in a reply
Posts: 63
Joined: 2005.12
Post: #3
You might be able to use the 'mod' field of the SDL keyboard event structure for this as well (IINM, it will represent the state of the modifier keys at the time the event was dispatched).

Note also that you'll probably want to process your events using a 'while' loop rather than an 'if' statement; otherwise, you may not consume all the events that are pending for that update, which may cause your app to appear unresponsive.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Spaces on Snow Leopard and ctrl/arrow keys GolfHacker 19 24,207 Dec 4, 2012 03:18 PM
Last Post: bmantzey
  [NSEvent keyCode] to actual keys? teknein 8 14,933 Sep 5, 2007 07:27 AM
Last Post: teknein
  Keys ......again Coin 7 8,268 Jan 29, 2005 09:38 PM
Last Post: belthaczar
  Keys I Can Use In Games Nick 10 7,387 Jul 22, 2004 11:49 PM
Last Post: AnotherJake
  Configurable keys - describe key that was pressed MattDiamond 13 9,216 Oct 27, 2003 11:23 PM
Last Post: OneSadCookie