The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL_TEXTINPUT happens too often
TheSHEEEP


Joined: 10 Feb 2014
Posts: 8
Hey there,

I am currently implementing text input into our application and am of course using SDL_TEXTINPUT for that.

Now for some reason I can't figure out, the SDL_TEXTINPUT event happens multiple times.
For example, pressing a yields two events, each containing "a".
Pressing ö,ä,ü or ß (German keyboard) and some other keys yields the event three times (so "ß", "ß", "ß" for example).

The reason is not key up and key down. All events are fired when the key is down.

Of course I could easily prevent this by checking for duplicate events, but if there is a better way to solve this, I'm open to suggestions Smile
TheSHEEEP


Joined: 10 Feb 2014
Posts: 8
Besides, even if there is no way to prevent this, I am curious about the reason behind this behavior.

Also, I am using SDL2 with MinGW on Windows. I did not test yet if the same thing happens on linux.
SDL_TEXTINPUT happens too often
Rainer Deyke
Guest

On 31.03.2015 11:11, TheSHEEEP wrote:
Quote:
Hey there,

I am currently implementing text input into our application and am of course using SDL_TEXTINPUT for that.

Now for some reason I can't figure out, the SDL_TEXTINPUT event happens multiple times.
For example, pressing a yields two events, each containing "a".
Pressing ö,ä,ü or ß (German keyboard) and some other keys yields the event three times (so "ß", "ß", "ß" for example).

It works for me, so my guess would be that the bug is on your side. Can
you post a minimal example program that demonstrates the problem?


--
Rainer Deyke

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL_TEXTINPUT happens too often
Bob Rubbens
Guest

A minimal example would be great. Are you maybe mixing up SDL_TEXTINPUT and SDL_TEXTEDITING events? Did you use SDL_StartTextInput() properly?


On 31 March 2015 at 15:08, Rainer Deyke wrote:
Quote:
On [url=tel:31.03.2015%2011]31.03.2015 11[/url]:11, TheSHEEEP wrote:
Quote:
Hey there,

I am currently implementing text input into our application and am of course using SDL_TEXTINPUT for that.

Now for some reason I can't figure out, the SDL_TEXTINPUT event happens multiple times.
For example, pressing a yields two events, each containing "a".
Pressing ö,ä,ü or ß (German keyboard) and some other keys yields the event three times (so "ß", "ß", "ß" for example).

It works for me, so my guess would be that the bug is on your side.  Can you post a minimal example program that demonstrates the problem?


--
Rainer Deyke

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL_TEXTINPUT happens too often
Daniel Gibson
Guest

On 03/31/2015 11:11 AM, TheSHEEEP wrote:
Quote:

The reason is not key up and key down. All events are fired when the key
is down.


If you're holding the button down for too long key repeat will kick in
(I /think/ the delay is controlled by your OS).

You might also want to tell us what exact version of SDL2 you're using
and which OS.

Cheers,
Daniel

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
TheSHEEEP


Joined: 10 Feb 2014
Posts: 8
The button is definitely not held down too long, and the repeated input when you do hold down a key for longer also works well.

The OS is Windows 8.1, and the SDL2 version is 2.0.1.

Quote:
Did you use SDL_StartTextInput() properly?

Define properly. Smile
I do call it when the application starts. I am aware that I could do this far more fine grained, but that is a lower priority task.
About the other event: I do not handle SDL_TEXTEDITING at all, as the GUI library I use handles that well on its own when injecting key down/up events.

A minimal example I cannot give you as the application is too complex.
The SDL input loop is this, however:
Code:
  SDL_PumpEvents();

    SDL_Event event;
    while (SDL_PollEvent(&event) != 0)
    {
        switch (event.type)
        {
            case SDL_MOUSEBUTTONDOWN:
            case SDL_MOUSEBUTTONUP:
                // Doing mouse button stuff
            break;
           
            case SDL_MOUSEMOTION:
                // Mouse motion stuff
            break;
           
            case SDL_MOUSEWHEEL:
                // Mouse wheel stuff
            break;
           
            case SDL_KEYDOWN:
            case SDL_KEYUP:
                // Key down/up stuff
                break;
               
            case SDL_TEXTINPUT:
            {
                // Text input handling,
                break;
            }
               
            default:
            break;
        }
    }

I stripped away our own code, but we do nothing with the events except reading them.
SDL_TEXTINPUT happens too often
Bob Rubbens
Guest

That's what I mean by properly. Your minimal example looks fine, except for the superfluous SDL_PumpEvents() (SDL_PollEvent should call it internally iirc) and the fact that it's maybe too minimal. Can you provide a minimal compileable example that replicates the bug? (So we can actually do g++ bug.cpp -lSDL2 or something similar and see for ourselves if it's indeed an SDL2 bug?) The minimal example in question doesn't need any of the code from your program, just make sure it contains the odd behaviour you describe.


Also, you say your GUI library "injects" keyup/keydown events? I'm probably misinterpreting it but it sounds suspicious. Maybe your gui library has functions for getting keyboard input so you don't have to pay attention to SDL_TEXTINPUT event? If there are, try those and see if your problem persists.


Lastly, is there a reason not to use SDL 2.0.3?


Just my 2 cents, sorry if I'm being too nosy :p



On 31 March 2015 at 15:59, TheSHEEEP wrote:
Quote:
The button is definitely not held down too long, and the repeated input when you do hold down a key for longer also works well.

The OS is Windows 8.1, and the SDL2 version is 2.0.1.




Quote:

Did you use SDL_StartTextInput() properly?



Define properly.
I do call it when the application starts. I am aware that I could do this far more fine grained, but that is a lower priority task.
About the other event: I do not handle SDL_TEXTEDITING at all, as the GUI library I use handles that well on its own when injecting key down/up events.

A minimal example I cannot give you as the application is too complex.
The SDL input loop is this, however:



Code:

  SDL_PumpEvents();

    SDL_Event event;
    while (SDL_PollEvent(&event) != 0)
    {
        switch (event.type)
        {
            case SDL_MOUSEBUTTONDOWN:
            case SDL_MOUSEBUTTONUP:
                // Doing mouse button stuff
            break;
           
            case SDL_MOUSEMOTION:
                // Mouse motion stuff
            break;
           
            case SDL_MOUSEWHEEL:
                // Mouse wheel stuff
            break;
           
            case SDL_KEYDOWN:
            case SDL_KEYUP:
                // Key down/up stuff
                break;
               
            case SDL_TEXTINPUT:
            {
                // Text input handling,
                break;
            }
               
            default:
            break;
        }
    }



I stripped away our own code, but we do nothing with the events except reading them.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Re: SDL_TEXTINPUT happens too often
TheSHEEEP


Joined: 10 Feb 2014
Posts: 8
Bob Rubbens wrote:
Also, you say your GUI library "injects" keyup/keydown events? I'm probably misinterpreting it but it sounds suspicious. Maybe your gui library has functions for getting keyboard input so you don't have to pay attention to SDL_TEXTINPUT event? If there are, try those and see if your problem persists.

No, I do inject key up/down events into the GUI library (CEGUI) Wink

For example, if there is a text field containing "aaabbb" and I inject a backspace down, it becomes "aaabb" on its own. I do not need to manually change any text (which I guess the TEXTEDIT event is for).

Bob Rubbens wrote:
Lastly, is there a reason not to use SDL 2.0.3?

No real reason other than us having no problems with the version we are currently using.
If we wanted to keep up with all recent releases of all libs we are using we would never get any actual work done Wink

I have the workaround implemented already (checking for duplicate events during an input loop), it is no big deal.
In light of that, finding out exactly what is going wrong is just too much effort atm, so sorry I can't give you a compilable example right now.
SDL_TEXTINPUT happens too often
Daniel Gibson
Guest

On 03/31/2015 04:42 PM, TheSHEEEP wrote:
Quote:
No real reason other than us having no problems with the version we are
currently using.

You do, otherwise you wouldn't be writing here Razz

Quote:
If we wanted to keep up with all recent releases of all libs we are
using we would never get any actual work done Wink

I have the workaround implemented already (checking for duplicate events
during an input loop), it is no big deal.

Sure that this won't fuck up if users actually want to keypresses?
Do you maybe insert chars for keydown events as well (you shouldn't.)?

BTW, as you're using CEGUI you have to translate SDL2 scancodes to
directinput/cegui scancodes. This may help:
https://github.com/DanielGibson/DOOM-3-BFG/blob/e37671d6ac408dc1029c50ddaa26e60e56759c7a/neo/sys/sdl/sdl2_scancode_mappings.h

Quote:
In light of that, finding out exactly what is going wrong is just too
much effort atm, so sorry I can't give you a compilable example right now.


Can you try to reproduce the problem with this minimal example, which
will print out textinput events (into sdl2_test_out.txt on Windows):
http://p.carnivore.it/5uDkS9

That should help you to check if the bug really is in SDL or in your code.

Cheers,
Daniel
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL_TEXTINPUT happens too often
Jonny D


Joined: 12 Sep 2009
Posts: 932
SDL 2.0.3 is a bug fix release.  So if you are experiencing a bug with the version you have, then you should try the latest release to make sure that it isn't something that was fixed years ago.

Jonny D





On Tue, Mar 31, 2015 at 10:42 AM, TheSHEEEP wrote:
Quote:



Bob Rubbens wrote:

Also, you say your GUI library "injects" keyup/keydown events? I'm probably misinterpreting it but it sounds suspicious. Maybe your gui library has functions for getting keyboard input so you don't have to pay attention to SDL_TEXTINPUT event? If there are, try those and see if your problem persists.



No, I do inject key up/down events into the GUI library (CEGUI)

For example, if there is a text field containing "aaabbb" and I inject a backspace down, it becomes "aaabb" on its own. I do not need to manually change any text (which I guess the TEXTEDIT event is for).




Bob Rubbens wrote:

Lastly, is there a reason not to use SDL 2.0.3?



No real reason other than us having no problems with the version we are currently using.
If we wanted to keep up with all recent releases of all libs we are using we would never get any actual work done

I have the workaround implemented already (checking for duplicate events during an input loop), it is no big deal.
In light of that, finding out exactly what is going wrong is just too much effort atm, so sorry I can't give you a compilable example right now.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org