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 2287

Summary: Duplicate SDL_TEXTINPUT events for a single key on Windows
Product: SDL Reporter: Amanieu d'Antras <amanieu>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED ABANDONED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: bugzilla-sdl
Version: 2.0.1   
Hardware: x86_64   
OS: Windows 7   
See Also: https://bugzilla.libsdl.org/show_bug.cgi?id=2406
https://bugzilla.libsdl.org/show_bug.cgi?id=1876

Description Amanieu d'Antras 2013-12-07 22:34:43 UTC
Sometimes when pressing a key both a WM_CHAR and a WM_KEYDOWN event are sent, which causes two SDL_TEXTINPUT events to be generated. This is due to https://hg.libsdl.org/SDL/rev/cc775832d501, which calls SDL_SendKeyboardText for WM_CHAR and WM_KEYDOWN.
Comment 1 Andreas Ertelt 2014-02-19 14:40:45 UTC
A real keystroke always only generates a WM_KEYDOWN event.

An optional WM_CHAR event is generated either by applications sending it directly or is generated by the call of TranslateMessage(&msg) which was removed by this patch because it is passing the correct keystrokes directly using SDL_SendKeyboardText(). TranslateMessage() does not produce correct information when the languages do not have an ASCII-compatible character set.

SDL_dxjoystick.c uses TranslateMessage() as well but I cannot quite see a reason as to why. Could that have been the real source of your problem?

https://hg.libsdl.org/SDL/rev/061ee02876e3 / https://hg.libsdl.org/SDL/rev/ce90b743882a have likely "solved" your problem by just ignoring WM_CHAR as well as WM_UNICHAR events sent to the application entirely which unfortunately was bad idea as well.

I would be very curious to know what exactly was going on in your case - do you have more information you could provide?
Comment 2 Amanieu d'Antras 2014-02-19 16:55:19 UTC
In my case I had a non-SDL window (pdcurses win32a) open in the same thread as an SDL window. This caused various issues, most noticeably this double input bug. I have worked around this by moving the non-SDL window into a separate thread.
Comment 3 Andreas Ertelt 2014-02-19 17:06:45 UTC
Could it be that your non-SDL window did the TranslateMessage()-step itself and then passed both events along to the SDL message handler?

I suppose to prevent such a case we could store the low word of a message field
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644958%28v=vs.85%29.aspx
to prevent that we don't process the same message twice, but I'm unsure if that would be acceptable behavior.
Comment 4 Sam Lantinga 2017-08-15 04:31:03 UTC
A bunch of the Windows input handling has been rewritten. Are you still getting this in the latest SDL snapshot?
http://www.libsdl.org/tmp/SDL-2.0.zip

Thanks!
Comment 5 Ryan C. Gordon 2018-08-06 21:20:19 UTC
Hello, and sorry if you're getting dozens of copies of this message by email.

We are closing out bugs that appear to be abandoned in some form. This can happen for lots of reasons: we couldn't reproduce it, conversation faded out, the bug was noted as fixed in a comment but we forgot to mark it resolved, the report is good but the fix is impractical, we fixed it a long time ago without realizing there was an associated report, etc.

Individually, any of these bugs might have a better resolution (such as WONTFIX or WORKSFORME or INVALID) but we've added a new resolution of ABANDONED to make this easily searchable and make it clear that it's not necessarily unreasonable to revive a given bug report.

So if this bug is still a going concern and you feel it should still be open: please feel free to reopen it! But unless you respond, we'd like to consider these bugs closed, as many of them are several years old and overwhelming our ability to prioritize recent issues.

(please note that hundred of bug reports were sorted through here, so we apologize for any human error. Just reopen the bug in that case!)

Thanks,
--ryan.