# Confused on how to handle (or why) SDL\_StartTextInput()?

**URL:** <https://discourse.libsdl.org/t/confused-on-how-to-handle-or-why-sdl-starttextinput/19857>\
**Category:** SDL Development\
**Created:** [August 14, 2013, 6:18am UTC](https://discourse.libsdl.org/t/confused-on-how-to-handle-or-why-sdl-starttextinput/19857 "2013-08-14T06:18:31Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![Alex\_Baines](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/alex_baines/32/2606_2.png) [@Alex\_Baines](https://discourse.libsdl.org/u/Alex_Baines)\
**Post date:** [February 27, 2015, 10:18pm UTC](https://discourse.libsdl.org/t/confused-on-how-to-handle-or-why-sdl-starttextinput/19857/15 "2015-02-27T22:18:15Z")

</div>

> OK, so, you agree that Jiang’s reply of getting SDL\_TEXTEDITING events for everything is just wrong, and that is ONLY useful for certain languages in some undescribed way. Forum post: [SDL :: View topic - Confused on how to handle (or why) SDL\_StartTextInput() ?](http://forums.libsdl.org/viewtopic.php?p=38620#38620)

I think Jian’s post assumes that you are using an IME, but most people  
aren’t, which is why it might be misleading.

> SDL\_TEXTEDITING gets fired always on windows(?) even when SDL\_StartTextInput() is _not_ called (see forum post [SDL :: View topic - Is it normal to get SDL\_TEXTEDITING events w/o SDL\_StartText](http://forums.libsdl.org/viewtopic.php?t=11060)), and still doesn’t contain any useful information.

I’m not sure why that would be the case. If the event has 0 length and  
you’re not using IME stuff, then I think it can be safely ignored.

> SDL\_TEXTINPUT is the one one that should always fire when a person types any key, and should also contain utf8 encoded translation of that key if needed, _but_, it does _not_ handle hitting backspace to delete the last character as was described in that post.  
> That means, that people handling SDL\_TEXTINPUT must write their own routine, and check if it is a multibyte sequence or not if a user presses backspace, and want to delete the last character(s).

Yes, I’ve had to do exactly that in my applications.

> How is it possible to test exactly when SDL\_TEXTEDITING contains actually useful information for something, since, AFAIK, SDL\_TEXTINPUT will _always_ contain the correct character be it “normal” or multibyte.

In the Linux code, the length parameter of SDL\_TEXTEDITING events can be  
used to see if it contains text. If it’s non-zero then you can display  
the text in some way which shows it’s in the process of being composed  
(Most non-SDL programs seem to underline this kind of text.)

> I have yet to see any full example of how SDL\_TEXTEDITING can be used for anything.  
> The wiki page for this is [https://wiki.libsdl.org/SDL\_TextEditingEvent](https://wiki.libsdl.org/SDL_TextEditingEvent) and it shows it is in dire need of more explanation when & how to handle this event.

Yes, the wiki page could definitely use some work. It does link to  
[https://wiki.libsdl.org/Tutorials/TextInput](https://wiki.libsdl.org/Tutorials/TextInput) though, which has a  
reasonable explanation of the system.

Basically, you should only need to look at SDL\_TEXTEDITING events if you  
want to render the currently-being-editing text used in IMEs.

There’s a hint “SDL\_IME\_INTERNAL\_EDITING” also, which allows you to just  
ignore the EDITING events entirely and let the OS do the rendering of  
this type of text if an IME is in use (It will just give you a TEXTINPUT  
when the user finishes composing). But I think it’s only implemented for  
the Linux code.On 27/02/15 21:54, Sparks wrote:

---

_[View the full topic](https://discourse.libsdl.org/t/confused-on-how-to-handle-or-why-sdl-starttextinput/19857)._
