Search code examples
c++textboxsdltextinput

SDL TextInput (using the new 1.3 structure)


Okay, I have been studying text input in SDL (how to turn the keystrokes data into letters and append them to a std::string called Text) and most of the tutorials have covered it this way:

//If a key was pressed
if(event->type == SDL_KEYDOWN )
{
        //If the key is a lowercase letter
        else if( (event->key.keysym.unicode >= (Uint16)'a' ) && (event->key.keysym.unicode <= (Uint16)'z' ) )
        {
            //Append the character
            Text += (char)event->key.keysym.unicode;
        }
}

However after some searching, I found a note in the SDL headers saying .unicode is deprecated and to use SDL_TextInputEvent/SDL_TextEditingEvent. There is some reference to it in the SDL documentation wiki, however I couldn't find any example on how to use it. For instance, how would I write the above snippet using the new structure?


Solution

  • You might give this tutorial a try.