We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3499 - SDL_TEXTINPUT sent when textinput is disabled on Windows
Summary: SDL_TEXTINPUT sent when textinput is disabled on Windows
Status: WAITING
Alias: None
Product: SDL
Classification: Unclassified
Component: events (show other bugs)
Version: HG 2.1
Hardware: x86_64 Windows (All)
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-22 20:12 UTC by echotangoecho
Modified: 2020-07-23 16:14 UTC (History)
3 users (show)

See Also:


Attachments
Test which shows the problem. (1.35 KB, text/x-c++src)
2016-11-22 20:12 UTC, echotangoecho
Details

Note You need to log in before you can comment on or make changes to this bug.
Description echotangoecho 2016-11-22 20:12:52 UTC
Created attachment 2639 [details]
Test which shows the problem.

When SDL_StartTextInput is called upon a key press of a character key on Windows, a SDL_TEXTINPUT event is received for this key, even though text input was not yet enabled when te key was pressed. The cause seems to be that TranslateMessage is called whether SDL_TEXTINPUT is enabled or not, causing a SDL_TEXTINPUT event to be generated when the WM_CHAR event is received after SDL_StartTextInput is called. The issue does indeed not seem to occur when TranslateMessage is only called if SDL_TEXTINPUT is enabled.
Comment 1 Sam Lantinga 2017-08-11 20:18:21 UTC
In SDL 2.0 text input events are enabled by default on the desktop. If you call SDL_StopTextInput() after creating your window, does that fix it for you?
Comment 2 echotangoecho 2017-08-17 08:55:12 UTC
That caused a related issue for us on Linux, but does not fix this on Windows. The exact problem in our case (0 A.D. / Pyrogenesis engine, also see bug report here: https://trac.wildfiregames.com/ticket/3870) is as follows: we use 't' as a hotkey to open a chat window, and when we call StartTextInput() upon a press of t, we don't expect to immediately also receive the character 't', we only expect to receive it upon repeat after StartTextInput() is called. The exact problem seems to be with this line: https://github.com/SDL-mirror/SDL/blob/f155bc23efc4734f96b021cf98b18843c87fd794/src/video/windows/SDL_windowsevents.c#L1016
A potential fix that has been confirmed to work for us is only executing this line if text input is actually enabled at this point -- The only problem with that is judging from the comment above this line it seems to be done intentionally...
Comment 3 Castro B 2019-10-05 10:20:15 UTC
@echotangoecho better this tahn nothing, I guess. ,https://couponaliexpress.nl/
Comment 4 Ryan C. Gordon 2020-03-24 22:54:20 UTC
(In reply to echotangoecho from comment #2)
> A potential fix that has been confirmed to work for us is only executing
> this line if text input is actually enabled at this point -- The only
> problem with that is judging from the comment above this line it seems to be
> done intentionally...

So this popped up in the recently-changed bugs list, compliments of a spam comment, but in case this is something that's still bothering you:

Are you getting your SDL events through a function used with SDL_AddEventWatch()?

Because we should be _way_ past the point where SDL_StartTextInput should be able to affect that keypress (the Windows event loop is long gone at this point, having copied SDL events to a queue for SDL_PollEvent() to find later), but I could see this happening in an event watcher, since your SDL_StartTextInput code would run before the event loop is complete.

--ryan.
Comment 5 Imarok 2020-07-23 16:14:29 UTC
(In reply to Ryan C. Gordon from comment #4)
> (In reply to echotangoecho from comment #2)
> > A potential fix that has been confirmed to work for us is only executing
> > this line if text input is actually enabled at this point -- The only
> > problem with that is judging from the comment above this line it seems to be
> > done intentionally...
> 
> So this popped up in the recently-changed bugs list, compliments of a spam
> comment, but in case this is something that's still bothering you:
> 
> Are you getting your SDL events through a function used with
> SDL_AddEventWatch()?
> 
> Because we should be _way_ past the point where SDL_StartTextInput should be
> able to affect that keypress (the Windows event loop is long gone at this
> point, having copied SDL events to a queue for SDL_PollEvent() to find
> later), but I could see this happening in an event watcher, since your
> SDL_StartTextInput code would run before the event loop is complete.
> 
> --ryan.

Yes this bug still happens and is bothering us.
I can't find a use of "SDL_AddEventWatch" anywhere in our code.
Btw: Have you seen the minimal working example uploaded by echotangoecho that shows the bug?