Sign in to follow this  

SDL keys

This topic is 4857 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

How can I detect keys like SDLK_QUESTION? I think it's behind shift on an american keyboard, but whatever I press, with or without shift, SDL never detects any key as being SDLK_QUESTION, and other similar keys like SDLK_AT, ... (SDLK_PERIOD works for example because that's not a key behind shift). Another question, for some reason KMOD_CAPS, KMOD_RSHIFT and KMOD_LSHIFT don't work, they're always false, wether or not caps lock is down, enabled or disabled, or left or right shift are pressed or not. How to use these KMODs? I'm writing a simple function to input text in SDL, which is why I encountered those questions. Everything works except the things above (currently I detect if shift is pressed with SDLK_LSHIFT etc... instead for capital letters). Thanks.

Share this post


Link to post
Share on other sites
Does anyone have a picture of the american keyboard layout (because that's what SDL uses), because I can't find one with google and don't know which keys are supposed to be behind other ones. Thanks :)

Share this post


Link to post
Share on other sites
If you want to know what character the user entered (as opposed to what key), try SDL_EnableUNICODE(1). event.keysym.unicode will now contain the (Uint16) character. You can usually simply cast it to a char and you'll have what you want.
One thing to keep in mind is that the unicode field will only be filled on keydown, not keyup.
You should also disable the unicode translation as soon as you're finished with it because it caused extra overhead.

Share this post


Link to post
Share on other sites
I'm wondering why you have to turn on unicode to get the ascii of the key? Simple SDL_getch() could have been nice.. I guess they'll write a library for it..
I don't know how symbols are arranged, but I guess you could write a routine to give an ascii equivalent for the key symbol:

return ascii_equivalent[keysym];

Share this post


Link to post
Share on other sites
The problem with that is that you have to write a different translation table for each keyboard.

The unicode translation uses whatever the operating system tells it, so it's always accurate. I'm guessing the reason that it's using unicode is to make sure all possible characters are possible. There's really no reason not to use it as it works on Win9x too without any special libraries (AFAIK at least).

Share this post


Link to post
Share on other sites
Quote:
Original post by Gyrbo
The problem with that is that you have to write a different translation table for each keyboard.


Does that mean that for example SDLK_z doesn't return z on all keyboards?
Btw, I noticed (by checking out SDL_keysym.h) that SDLK-symbols are mapped to ascii if it's less than SDLK_z.

Share this post


Link to post
Share on other sites
Feidias: yes, you're right. I'm currently typing on an AZERTY keyboard and I have to use the "w" key if I want to generate an SDLK_z event.

You don't really need the exact letter a key represents most of the type, except for entering your name or something. In those cases, I enable unicode translation to get the key and after the name has been entered, I switch it back off.

I presonally like the way SDL does it, because this way I can still use the WASD keys without doing strange things with my fingers. (Try using Q to strafe left, D to strafe right, Z to move forward and S to move backwards if you have a QWERTY keyboard and you'll get the idea).

Share this post


Link to post
Share on other sites

This topic is 4857 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.

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