# 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:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sparks](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ee7513/32.png) [@Sparks](https://discourse.libsdl.org/u/Sparks)\
**Post date:** [August 14, 2013, 6:18am UTC](https://discourse.libsdl.org/t/confused-on-how-to-handle-or-why-sdl-starttextinput/19857/1 "2013-08-14T06:18:31Z")

</div>

With SDL 1.2, we did the normal(?) way of SDL\_EnableUNICODE(1) and then for each character, we received via keyEvent-\>keysym.unicode, we would add it to our input buffer to make the unicode string.

With SDL 2.0, both those have been removed, and it mentions to use the new text input API.  
However, I am not clear the exact reason to use said new text input API, instead of using the old method (which would require a workaround since those are gone).

Let’s say the t key is used for communications.  
When we detect that the t key is pressed, we would then start SDL\_StartTextInput(), and then in event loop, we would keep getting SDL\_TEXTINPUT events as the user types, but since they could be also hitting other hotkeys (like Function keys or tab or…), wouldn’t all this be in the unicode string as well, so we would need a way to filter non ASCII (or non readable) keys from that right?  
Then if they want to edit said chat string, (hit backspace or use arrow keys) then we get SDL\_TextEditingEvent events on those, is any of that filtered out as well?  
Then finally, when in SDL\_StartTextInput() mode, we wait for them to hit the enter key, and then do SDL\_StopTextInput(), which would give us the final unicode string correct?

This brings up SDL\_SetTextInputRect(), just how does this play into things? It says: “Use this function to set the rectangle used to type Unicode text inputs.”, is this supposed to be the buffer limit of the text, so, if we wanted 80 chars max, we would set this to 80? Or is this for something else?

I just don’t see the need for this for games, the old way handled unicode input just fine, never had any bug reports, so, just why should we use the new way with all the extra processing required for the new logic & event loops? We still need to advance the cursor in the game for every character they type, so I guess I am just missing something with the new text API.

Maybe someone can help clear the fog about this?

---

<div class="post-metadata">

**Author:** ![Sik\_the\_hedgehog](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/db5fbb/32.png) [@Sik\_the\_hedgehog](https://discourse.libsdl.org/u/Sik_the_hedgehog)\
**Post date:** [August 14, 2013, 7:05am UTC](https://discourse.libsdl.org/t/confused-on-how-to-handle-or-why-sdl-starttextinput/19857/2 "2013-08-14T07:05:04Z")

</div>

The old way of handling Unicode didn’t work well with any input system  
that allows entering multiple characters at the same time (Asian input  
systems are extremely guilty of this, saying this as somebody who has  
Japanese input support installed on his system).

And yeah, I also still have no idea how SDL\_SetTextInputRect is  
supposed to work. I only know it influences where the candidate list  
appears on screen (the candidate list is a list that shows different  
texts that you can enter with the specified input, e.g. different  
kanji for the same word, etc.).

---

<div class="post-metadata">

**Author:** ![slouken](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ec9cab/32.png) [@slouken](https://discourse.libsdl.org/u/slouken)\
**Post date:** [August 14, 2013, 7:09am UTC](https://discourse.libsdl.org/t/confused-on-how-to-handle-or-why-sdl-starttextinput/19857/3 "2013-08-14T07:09:01Z")

</div>

If you just want American and Western European language support on desktop  
systems, you can ignore those functions. They’re for more advanced  
international input with IMEs and mobile devices.

Cheers!On Tue, Aug 13, 2013 at 11:18 PM, Sparks wrote:

> \*\*  
> With SDL 1.2, we did the normal(?) way of SDL\_EnableUNICODE(1) and then  
> for each character, we received via keyEvent-\>keysym.unicode, we would add  
> it to our input buffer to make the unicode string.
> 
> With SDL 2.0, both those have been removed, and it mentions to use the new  
> text input API.  
> However, I am not clear the exact reason to use said new text input API,  
> instead of using the old method (which would require a workaround since  
> those are gone).
> 
> Let’s say the t key is used for communications.  
> When we detect that the t key is pressed, we would then start  
> SDL\_StartTextInput(), and then in event loop, we would keep getting  
> SDL\_TEXTINPUT events as the user types, but since they could be also  
> hitting other hotkeys (like Function keys or tab or…), wouldn’t all this  
> be in the unicode string as well, so we would need a way to filter non  
> ASCII (or non readable) keys from that right?  
> Then if they want to edit said chat string, (hit backspace or use arrow  
> keys) then we get SDL\_TextEditingEvent events on those, is any of that  
> filtered out as well?  
> Then finally, when in SDL\_StartTextInput() mode, we wait for them to hit  
> the enter key, and then do SDL\_StopTextInput(), which would give us the  
> final unicode string correct?
> 
> This brings up SDL\_SetTextInputRect(), just how does this play into  
> things? It says: “Use this function to set the rectangle used to type  
> Unicode text inputs.”, is this supposed to be the buffer limit of the text,  
> so, if we wanted 80 chars max, we would set this to 80? Or is this for  
> something else?
> 
> I just don’t see the need for this for games, the old way handled unicode  
> input just fine, never had any bug reports, so, just why should we use the  
> new way with all the extra processing required for the new logic & event  
> loops? We still need to advance the cursor in the game for every character  
> they type, so I guess I am just missing something with the new text API.
> 
> Maybe someone can help clear the fog about this?
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![Jiang\_Jiang](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/jiang_jiang/32/819_2.png) [@Jiang\_Jiang](https://discourse.libsdl.org/u/Jiang_Jiang)\
**Post date:** [August 14, 2013, 8:14am UTC](https://discourse.libsdl.org/t/confused-on-how-to-handle-or-why-sdl-starttextinput/19857/4 "2013-08-14T08:14:05Z")

</div>

> With SDL 1.2, we did the normal(?) way of SDL\_EnableUNICODE(1) and then for each character, we received via keyEvent-\>keysym.unicode, we would add it to our input buffer to make the unicode string.
> 
> With SDL 2.0, both those have been removed, and it mentions to use the new text input API.  
> However, I am not clear the exact reason to use said new text input API, instead of using the old method (which would require a workaround since those are gone).
> 
> Let’s say the t key is used for communications.  
> When we detect that the t key is pressed, we would then start SDL\_StartTextInput(), and then in event loop, we would keep getting SDL\_TEXTINPUT events as the user types, but since they could be also hitting other hotkeys (like Function keys or tab or…), wouldn’t all this be in the unicode string as well, so we would need a way to filter non ASCII (or non readable) keys from that right?  
> Then if they want to edit said chat string, (hit backspace or use arrow keys) then we get SDL\_TextEditingEvent events on those, is any of that filtered out as well?

In a typical GUI application, the OS will be responsible for telling  
you the candidate text (via SDL\_TEXTEDITING), you can choose how (and  
where) to show it in your UI.

Let’s say with an input method I typed “abc” and got unicode character  
“X”, the SDL application will first receive three SDL\_TEXTEDITING  
events with ‘a’, ‘ab’ and ‘abc’, then finally receive SDL\_TEXTINPUT  
event with unicode character ‘X’.

During this text compositing process, user can press any arbitrary  
keys such as Function, backspace, both the SDL application and OS  
input method will receive it and decide whether to deal with these  
keys or not. For instance when user press backspace, most input  
methods will delete the last candidate character typed and SDL app  
will receive a new SDL\_TEXTEDITING event (let’s say user typed a, b,  
backspace, c, then the application will receive 4 events containing  
‘a’, ‘ab’, ‘a’, ‘ac’ each).

> Then finally, when in SDL\_StartTextInput() mode, we wait for them to hit the enter key, and then do SDL\_StopTextInput(), which would give us the final unicode string correct?

You can wait until the enter key or other events (ESC or mouse click?)  
defined by your application.

> This brings up SDL\_SetTextInputRect(), just how does this play into things? It says: “Use this function to set the rectangle used to type Unicode text inputs.”, is this supposed to be the buffer limit of the text, so, if we wanted 80 chars max, we would set this to 80? Or is this for something else?

SDL\_SetTextInputRect() gives the OS a hint for where to show the  
candidate text list, since the OS doesn’t know where you want to draw  
the text you received via SDL\_TEXTEDITING event.

- JiangOn Wed, Aug 14, 2013 at 8:18 AM, Sparks wrote:

---

<div class="post-metadata">

**Author:** ![Sik\_the\_hedgehog](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/db5fbb/32.png) [@Sik\_the\_hedgehog](https://discourse.libsdl.org/u/Sik_the_hedgehog)\
**Post date:** [August 14, 2013, 8:21am UTC](https://discourse.libsdl.org/t/confused-on-how-to-handle-or-why-sdl-starttextinput/19857/5 "2013-08-14T08:21:42Z")

</div>

2013/8/14, Jiang Jiang :

> SDL\_SetTextInputRect() gives the OS a hint for where to show the  
> candidate text list, since the OS doesn’t know where you want to draw  
> the text you received via SDL\_TEXTEDITING event.

The documentation isn’t even remotely clear about this though. Exactly  
which area one should be expected to cover with that rectangle? I.e.  
which coordinates one should specify.

---

<div class="post-metadata">

**Author:** ![Jiang\_Jiang](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/jiang_jiang/32/819_2.png) [@Jiang\_Jiang](https://discourse.libsdl.org/u/Jiang_Jiang)\
**Post date:** [August 14, 2013, 8:31am UTC](https://discourse.libsdl.org/t/confused-on-how-to-handle-or-why-sdl-starttextinput/19857/6 "2013-08-14T08:31:17Z")

</div>

Sorry that hasn’t been very clear. I should probably clarify this and  
write a dedicated post.

You can take a look at this little demo and play with it (with your  
system IME on):

> <https://github.com/libsdl-org/SDL/blob/67367be0197e9a398ab4ee50afdb155f43bd1c62/test/testime.c>

The rectangle is supposed to be the rectangle that covered the “marked  
text” you received from SDL\_TEXTEDITING.

Certain programs might choose to show a text field at the bottom of  
the application, then the marked text will be drawn in this text field  
at the bottom. But it’s really up to you to decide. (For instance  
games like Quake can pull down a console screen for users to type  
text, then the marked text will be drawn somewhere in this console  
screen.)

- JiangOn Wed, Aug 14, 2013 at 10:21 AM, Sik the hedgehog \<sik.the.hedgehog at [gmail.com](http://gmail.com)\> wrote:

> 2013/8/14, Jiang Jiang \<@Jiang\_Jiang\>:
> 
> > SDL\_SetTextInputRect() gives the OS a hint for where to show the  
> > candidate text list, since the OS doesn’t know where you want to draw  
> > the text you received via SDL\_TEXTEDITING event.
> 
> The documentation isn’t even remotely clear about this though. Exactly  
> which area one should be expected to cover with that rectangle? I.e.  
> which coordinates one should specify.

---

<div class="post-metadata">

**Author:** ![john\_skaller](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/j/58956e/32.png) [@john\_skaller](https://discourse.libsdl.org/u/john_skaller)\
**Post date:** [August 14, 2013, 8:42am UTC](https://discourse.libsdl.org/t/confused-on-how-to-handle-or-why-sdl-starttextinput/19857/7 "2013-08-14T08:42:36Z")

</div>

> In a typical GUI application, the OS will be responsible for telling  
> you the candidate text (via SDL\_TEXTEDITING), you can choose how (and  
> where) to show it in your UI.

I found this explanation so good I added it to the Wiki  
under SDL\_TextInputEvent. Hope you don’t mind!  
[With a credit]On 14/08/2013, at 6:14 PM, Jiang Jiang wrote:

–  
john skaller  
@john_skaller  
[http://felix-lang.org](http://felix-lang.org)

---

<div class="post-metadata">

**Author:** ![Sparks](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ee7513/32.png) [@Sparks](https://discourse.libsdl.org/u/Sparks)\
**Post date:** [February 27, 2015, 7:37pm UTC](https://discourse.libsdl.org/t/confused-on-how-to-handle-or-why-sdl-starttextinput/19857/8 "2015-02-27T19:37:54Z")

</div>

Jiang Jiang wrote:

> In a typical GUI application, the OS will be responsible for telling  
> you the candidate text (via SDL\_TEXTEDITING), you can choose how (and  
> where) to show it in your UI.
> 
> Let’s say with an input method I typed “abc” and got unicode character  
> “X”, the SDL application will first receive three SDL\_TEXTEDITING  
> events with ‘a’, ‘ab’ and ‘abc’, then finally receive SDL\_TEXTINPUT  
> event with unicode character ‘X’.

This seems wrong.  
Starting SDL\_StartTextInput(), what happens is:  
“a” is enterned.  
SDL\_TEXTINPUT event fired, and we see “a”  
_NO_ SDL\_TEXTEDITING event fired.  
“b” is entered.  
SDL\_TEXTINPUT event fired, and we see “b”  
_NO_ SDL\_TEXTEDITING event fired.  
…same for “c”  
Now, I enter in “”  
SDL\_TEXTEDITING event fired, but no text in event.edit.text

Code:

- 

```
  edit	{type=770 timestamp=423318 windowID=1 ...}	SDL_TextEditingEvent
  type	770	unsigned int
  timestamp	423318	unsigned int
  windowID	1	unsigned int

```

- 

```
  text	0x0037f794 ""	char[32]
  start	0	int
  length	0	int

```

SDL\_TEXTINPUT fired, that does have the “abc” string.  
That isn’t how Jiang described would happen.

> During this text compositing process, user can press any arbitrary  
> keys such as Function, backspace, both the SDL application and OS  
> input method will receive it and decide whether to deal with these  
> keys or not. For instance when user press backspace, most input  
> methods will delete the last candidate character typed and SDL app  
> will receive a new SDL\_TEXTEDITING event (let’s say user typed a, b,  
> backspace, c, then the application will receive 4 events containing  
> ‘a’, ‘ab’, ‘a’, ‘ac’ each).

Nope, it doesn’t do that.  
“a"is entered fires SDL\_TEXTINPUT event, string has"a”  
“b” is entered fires SDL\_TEXTINPUT event, string has “ab”  
backspace is hit, fires SDL\_TEXTEDITING event:

Code:

- 

```
  edit	{type=770 timestamp=152924 windowID=1 ...}	SDL_TextEditingEvent
  type	770	unsigned int
  timestamp	152924	unsigned int
  windowID	1	unsigned int

```

- 

```
  text	0x0038f84c ""	char[32]
  start	0	int
  length	0	int

```

string has “abc”

So, I am still confused on how all this is supposed to work.  
SDL\_TEXTEDITING doesn’t seem to be working at all as described here.

---

<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, 8:21pm UTC](https://discourse.libsdl.org/t/confused-on-how-to-handle-or-why-sdl-starttextinput/19857/9 "2015-02-27T20:21:14Z")

</div>

Which OS and Input method are you using?On 27/02/15 19:37, Sparks wrote:

> SDL\_TEXTINPUT fired, that does have the “abc” string.  
> That isn’t how Jiang described would happen.

---

<div class="post-metadata">

**Author:** ![Sparks](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ee7513/32.png) [@Sparks](https://discourse.libsdl.org/u/Sparks)\
**Post date:** [February 27, 2015, 8:32pm UTC](https://discourse.libsdl.org/t/confused-on-how-to-handle-or-why-sdl-starttextinput/19857/10 "2015-02-27T20:32:33Z")

</div>

Alex Baines wrote:\> On 27/02/15 19:37, Sparks wrote:

> > SDL\_TEXTINPUT fired, that does have the “abc” string.  
> > That isn’t how Jiang described would happen.
> 
> Which OS and Input method are you using?

Windows 7.  
What do you mean what input method?  
I just enable SDL\_StartTextInput(), SDL\_Init(SDL\_INIT\_VIDEO | SDL\_INIT\_TIMER)…then sit in a loop looking for events.

---

<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, 8:47pm UTC](https://discourse.libsdl.org/t/confused-on-how-to-handle-or-why-sdl-starttextinput/19857/11 "2015-02-27T20:47:03Z")

</div>

By input method I mean how you are entering the special character that  
is causing the issue.

Since you’re using Windows 7 I probably can’t be of much help though,  
I’m only familiar with SDL’s Linux text input code.On 27/02/15 20:32, Sparks wrote:

> Windows 7.  
> What do you mean what input method?  
> I just enable SDL\_StartTextInput(), SDL\_Init(SDL\_INIT\_VIDEO | SDL\_INIT\_TIMER)…then sit in a loop looking for events.

---

<div class="post-metadata">

**Author:** ![Sparks](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ee7513/32.png) [@Sparks](https://discourse.libsdl.org/u/Sparks)\
**Post date:** [February 27, 2015, 8:55pm UTC](https://discourse.libsdl.org/t/confused-on-how-to-handle-or-why-sdl-starttextinput/19857/12 "2015-02-27T20:55:21Z")

</div>

Alex Baines wrote:\> On 27/02/15 20:32, Sparks wrote:

> > Windows 7.  
> > What do you mean what input method?  
> > I just enable SDL\_StartTextInput(), SDL\_Init(SDL\_INIT\_VIDEO | SDL\_INIT\_TIMER)…then sit in a loop looking for events.
> 
> By input method I mean how you are entering the special character that  
> is causing the issue.
> 
> Since you’re using Windows 7 I probably can’t be of much help though,  
> I’m only familiar with SDL’s Linux text input code.
> 
> * * *

It isn’t just that 1 unicode character that is causing the issue, it is the whole description of the process that is flawed.  
Getting SDL\_TEXTINPUT instead of SDL\_TEXTEDITING events, and then those SDL\_TEXTEDITING being worthless (no text, start & length being 0).  
I enter unicode via the alt-keypad method, but, I don’t think this matters much, since, this isn’t the main issue here.

---

<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, 9:09pm UTC](https://discourse.libsdl.org/t/confused-on-how-to-handle-or-why-sdl-starttextinput/19857/13 "2015-02-27T21:09:56Z")

</div>

> It isn’t just that 1 unicode character that is causing the issue, it is the whole description of the process that is flawed.  
> Getting SDL\_TEXTINPUT instead of SDL\_TEXTEDITING events, and then those SDL\_TEXTEDITING being worthless (no text, start & length being 0).  
> I enter unicode via the alt-keypad method, but, I don’t think this matters much, since, this isn’t the main issue here.

if you’re using an input method that composes multiple keystrokes into  
characters - or does some operation to them before they are committed.

These are mostly used for input of Asian languages which have many more  
characters than keyboard keys, and require pressing a key sequence to  
enter a specific character.

If you’re not using anything like that, then you should get one  
SDL\_TEXTINPUT event per key, each of which should usually contain just a  
single character. You have to stitch the characters together yourself.

I don’t know how the ALT+Code stuff is handled by SDL or if it uses  
SDL\_TEXTEDITING or not, and I don’t know why you’re getting a single  
SDL\_TEXTINPUT event with 4 characters in it.On 27/02/15 20:55, Sparks wrote:

> From my understanding, you’ll only get meaningful SDL\_TEXTEDITING events

---

<div class="post-metadata">

**Author:** ![Sparks](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ee7513/32.png) [@Sparks](https://discourse.libsdl.org/u/Sparks)\
**Post date:** [February 27, 2015, 9:54pm UTC](https://discourse.libsdl.org/t/confused-on-how-to-handle-or-why-sdl-starttextinput/19857/14 "2015-02-27T21:54:05Z")

</div>

Alex Baines wrote:\> On 27/02/15 20:55, Sparks wrote:

> > It isn’t just that 1 unicode character that is causing the issue, it is the whole description of the process that is flawed.  
> > Getting SDL\_TEXTINPUT instead of SDL\_TEXTEDITING events, and then those SDL\_TEXTEDITING being worthless (no text, start & length being 0).  
> > I enter unicode via the alt-keypad method, but, I don’t think this matters much, since, this isn’t the main issue here.
> 
> From my understanding, you’ll only get meaningful SDL\_TEXTEDITING events  
> if you’re using an input method that composes multiple keystrokes into  
> characters - or does some operation to them before they are committed.
> 
> These are mostly used for input of Asian languages which have many more  
> characters than keyboard keys, and require pressing a key sequence to  
> enter a specific character.
> 
> If you’re not using anything like that, then you should get one  
> SDL\_TEXTINPUT event per key, each of which should usually contain just a  
> single character. You have to stitch the characters together yourself.

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)

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.

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).

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.

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.

---

<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:

---

<div class="post-metadata">

**Author:** ![Dennis](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/e56c9b/32.png) [@Dennis](https://discourse.libsdl.org/u/Dennis)\
**Post date:** [March 21, 2015, 1:18pm UTC](https://discourse.libsdl.org/t/confused-on-how-to-handle-or-why-sdl-starttextinput/19857/16 "2015-03-21T13:18:03Z")

</div>

I’m sorry that I can’ write English well, the sentences I write may be less polite and not clear? Sorry ☹

My case is the same as what Sparks said,I don’t think Jian’s post is right.  
And there are some other issues:  
Status Window , Composition Window and Candidates Window both disappear ,  
I can’t use the IME at all.  
However, I find that there is a possible way to solve it: (Thanks for ancientcc )  
[http://www.freeors.com/bbs/forum.php?mod=viewthread&tid=22189&extra=page%3D1%26filter%3Dtypeid%26typeid%3D40[/url]](http://www.freeors.com/bbs/forum.php?mod=viewthread&tid=22189&extra=page%3D1%26filter%3Dtypeid%26typeid%3D40%5B/url%5D)

there is the translation of the article above ^  
(I am not sure it is a accurate translation. Sorry [Embarassed]

I can’t see the Status Window:  
Fix: make WM\_IME\_NOTIFY return SDL\_FALSE default  
I can’t see the Composition Window:  
Fix: make WM\_IME\_STARTCOMPOSITION return SDL\_FALSEe  
It only shows one char in the Composition Window:  
Fix: make WM\_IME\_COMPOSITION return SDL\_FALSE when GCS\_COMPSTR  
What’s more, in SDL 2.0.3,if IMN\_CLOSECANDIDATE are not SDL\_TURE , it is no way to type some chinese char by some IME. (for example,the character “?” can’t type by WBJJ inputting method)

I haven’t tried the fix above.
