SDL 2: How to read shift+X keys? |
Sparks
|
https://wiki.libsdl.org/SDLKeycodeLookup
Here, it shows (for example) 33 = 0x21 ('!') = SDLK_EXCLAIM. https://wiki.libsdl.org/SDL_Scancode Here it shows "!" = (none) = SDLK_EXCLAIM. In the event loop I check for SDL_KEYDOWN, and then do, SDL_GetScancodeName(event->key.keysym.scancode), and it shows "1", and SDL_GetKeyName(event->key.keysym.sym) also shows "1" instead of showing "!". I then try shift + "a" (should be "A") but, it shows "a". What am I missing here? |
|||||||||||
|
SDL 2: How to read shift+X keys? |
Jonny D
|
What you are missing is the SDL_TEXTINPUT event. See here:https://wiki.libsdl.org/SDL_TextInputEvent
Call SDL_StartTextInput(), then start checking for SDL_TEXTINPUT events. Use the characters that the event gives you. This is a change from SDL1.2, where properly dealing with different keyboard layouts, input devices (e.g. mobile virtual keyboard), and different character sets (or Unicode) was not possible. Jonny D On Thu, Feb 26, 2015 at 3:48 PM, Sparks wrote:
|
|||||||||||||
|
Re: SDL 2: How to read shift+X keys? |
Sparks
|
Yes, I know about this, but, that isn't what I need, SDL_TEXTINPUT is too limiting with having to do SDL_Start/StopTextInput() when we want keyboard input, since other keys can be used at the same time. That is why we must manually do this, like the "old" way, which seems broken now?
If both the scancode and the keycode both have "!" as an entry, then, it should be possible to have "!" given in the keycode or scancode. Uppercase 'A' should be value 65, lower case 'a' should be 97 according to the ASCII table, that is the same behavior we want with SDL 2.
|
|||||||||||||||
|
Re: SDL 2: How to read shift+X keys? |
Sparks
|
Just to make it more clear, before SDL 1 had this struct typedef struct{ Uint8 scancode; SDLKey sym; SDLMod mod; Uint16 unicode; } SDL_keysym; Where SDL_keysym.unicode would have, in this case contained "!" and "A" respectively. The SDL_keysym.sym would have been "1" and "a" respectively in my example. That is what I need, and I can't seem to find a way to mimic that behavior anymore? |
|||||||||||||
|
SDL 2: How to read shift+X keys? |
Jonny D
|
What would be wrong with using SDL_StartTextInput() and leaving it on for desktop systems? You would do the same processing, unless I'm misunderstanding what you're doing.
Alternatively, use SDL_GetModState() and you can then shift certain ascii values yourself. Jonny D On Thu, Feb 26, 2015 at 5:17 PM, Sparks wrote:
|
|||||||||||||
|
SDL 2: How to read shift+X keys? |
Daniel Gibson
Guest
|
On 02/27/2015 12:49 AM, Jonathan Dearborn wrote:
Agree.
Bad idea.. this might somehow work for a-z, but will utterly fail at all other keys (including numbers), because of different keyboard layouts. Just use SDL_TEXTINPUT events for textinput. It's really worth the effort. Cheers, Daniel
_______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||||||
|
Re: SDL 2: How to read shift+X keys? |
Sparks
|
I thought if you leave SDL_StartTextInput() 'on', that it would swallow up all key presses from that point on, until you turn that off? Do you still get SDL_KEYDOWN events, along with SDL_TEXTINPUT & SDL_TEXTEDITING events? In other words, would I get a SDL_KEYDOWN event for pressing "shift a" (would generate a 'a'), and that will be "A" in the SDL_TEXTINPUT event? |
|||||||||||||
|
SDL 2: How to read shift+X keys? |
Jonny D
|
Yeah, you still get SDL_KEYDOWN when it is on. That way you can handle non-printing keys too (like backspace).
Good luck! Jonny D On Thu, Feb 26, 2015 at 7:14 PM, Sparks wrote:
|
|||||||||||||
|
Quick Question |
trevor.shawn.williams
|
What exactly are you trying to do? I can't tell from the conversation if you're trying to issue alternate game commands if a mod key is pressed (press 'w' to walk, press 'w' + 'Shift' to run) or implement some kind of text input interface like a chat client. Is your initial post the results of debugging or do you really need the character output? Sorry if you've made it clear, and I've just missed it.
|
|||||||||||
|
Re: SDL 2: How to read shift+X keys? |
mbabuskov
|
Yes.
Yes, exactly. You can use SDL_KEYDOWN to detect stuff like Backspace to erase the last char or ESC being pressed to cancel editing. |
|||||||||||||||
|