Jump to content
  • Advertisement
Sign in to follow this  

[SDL] Capslock as "normal" key

This topic is 4133 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys Since libSDL.org currently has some problems with it's wikis and tutorials I need to ask a stupid question: My small program uses SDL. Basically for everything - Video, Audio, Input etc. Now I want to use CAPSLOCK as well. But as the ordinary behaviour of CAPSLOCK the key does not send the release signal if the key is not pressed anymore. To get the release I need to press the key again. That's pretty normal to me but I wonder if there is a possibility to make CAPSLOCK a normal key that gets released when I don't press the key anymore. I read about some patches to hack into the SDL source, but that is no possibility for me. I would like to solve it in my program itself - IF it is actually possible. Does anyone know a solution? Thanks

Share this post


Link to post
Share on other sites
Advertisement
I believe this aspect of SDL can't be changed at runtime. I've complained about it about 1,000,000 times to the SDL mailing list over the years, but a fix is still not forthcoming. The source of the problem is that old Apple Desktop Bus (like USB but pre-USB, used by Apple for keyboards, mice and other human input stuff up until about 1997, and then for a while more internally inside their laptops) keyboards and the keyboards for some esoteric UNIX workstations only give keydown when the key is pressed the first time and key up when they are released the next time. So SDL apps would see weird caps/num lock behaviour on those machines and no others.

Out of interest, why can't you patch and rebuild SDL? Would you be able to use a modified SDL.dll if one were provided? The change is just a tiny little alteration to the function SDL_PrivateKeyboard in src/events/SDL_keyboard.c and is incredibly easy to figure out even if it wasn't documented.

Share this post


Link to post
Share on other sites
Hm thanks for your info.

Well I don't really want to change SDL itself. If I would only be on windows we could do it, but I also provide my program for Linux and I don't want to "force" every user to change his/her SDL version installed.
That's not worth for this small feature I planned...

Share this post


Link to post
Share on other sites
Well it tells me if the key is pressed. But it does not gives me the chance to alter the event when I don't press the key anymore...

This exmplains it very well:
http://gpwiki.org/index.php/C:SDL_Keyboard_Input_using_an_Event_Loop

When I compile this it shows me every key that I press or release. But CAPS LOCK only gets released when I press the key again.

Share this post


Link to post
Share on other sites
Well SDL_GetKeyState() isn't an event. It just returns a boolean array of all keys that were pressed when it was run.

So if you wanted, you could have it run every frame and check for the capslock key. If it returns true this frame and false the next then you can assume the key was pressed and then released.


//MainLoop
while(NotStopped)
{
<event handling>

uint8 *Keys=SDL_GetKeyState(NULL);
if(Keys[SDLK_CAPSLOCK]) // if the key was pressed
{
//do stuff
}

<the rest of your stuff>
}



Something like that. Perhaps have a second Keys, say LastKeys, that holds the values for the last frame. That would give you the comparison you need.

If it works, I don't know- I've never tried to used capslock in SDL.

Oh, and I'm not sure if the value is SDLK_CAPSLOCK, it's probably something else as this was a guess. You should probably check the doc if you plan to try this.

Hope that helped...
-Artum.

Share this post


Link to post
Share on other sites
Unfortunately, SDL_GetKeyState gives exactly the same results as following keyup/keydown events in your own code — so the caps lock key has exactly the same behaviour there as it does in the event queue.

Share this post


Link to post
Share on other sites
Well basically I could hack something so my program would read every change of the state... but that would not solve what would happen WHILE I have the key pressed actually (having my finger on it for a random period of time).

However it is really not THAT improtant. Even not so important to change SDL. Basically I just wanted to know if there is a common solution SDL offers ... but I already guessed there is not and I can understand that.

Thanks for all the replies so far :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!