Multiple Keys down in SDL
Hi,
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:
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?
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:
Code:
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");
break;
default:
break;
}
}
}
}
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?
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.
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.
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.
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
Spaces on Snow Leopard and ctrl/arrow keys | GolfHacker | 19 | 26,793 |
Dec 4, 2012 03:18 PM Last Post: bmantzey |
|
[NSEvent keyCode] to actual keys? | teknein | 8 | 16,575 |
Sep 5, 2007 07:27 AM Last Post: teknein |
|
Keys ......again | Coin | 7 | 9,081 |
Jan 29, 2005 09:38 PM Last Post: belthaczar |
|
Keys I Can Use In Games | Nick | 10 | 8,318 |
Jul 22, 2004 11:49 PM Last Post: AnotherJake |
|
Configurable keys - describe key that was pressed | MattDiamond | 13 | 10,602 |
Oct 27, 2003 11:23 PM Last Post: OneSadCookie |