Skip to content

Commit b5bb7c6

Browse files
authored
Merge pull request pygame#1398 from pygame/keydown-unicode_modifiers2
Maybe fix the keydown unicode attribute on windows.
2 parents e4ca835 + 86bcf5a commit b5bb7c6

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src_c/event.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,34 @@ pg_event_filter(void *_, SDL_Event *event)
148148
_pg_repeat_timer = SDL_AddTimer(pg_key_repeat_delay, _pg_repeat_callback,
149149
NULL);
150150
}
151+
#ifdef WIN32
152+
/* This does not seem to work on Mac 10.13. */
153+
#pragma PG_WARN(PumpEvents is not thread-safe)
154+
SDL_PumpEvents();
155+
if (SDL_PeepEvents(inputEvent, 1, SDL_PEEKEVENT,
156+
SDL_TEXTINPUT, SDL_TEXTINPUT) == 1)
157+
{
158+
SDL_Event *ev = inputEvent;
159+
SDL_PumpEvents();
160+
if (_pg_last_unicode_char[0] == 0) {
161+
if (SDL_PeepEvents(inputEvent, 2, SDL_PEEKEVENT,
162+
SDL_TEXTINPUT, SDL_TEXTINPUT) == 2)
163+
ev = &inputEvent[1];
164+
}
151165

166+
/* Only copy size - 1. This will always leave the string
167+
* terminated with a 0. */
168+
strncpy(_pg_last_unicode_char, ev->text.text,
169+
sizeof(_pg_last_unicode_char) - 1);
170+
}
171+
else {
172+
_pg_last_unicode_char[0] = 0;
173+
}
174+
#else
152175
_pg_last_unicode_char[0] = 0;
153176
/* store the keydown event for later in the SDL_TEXTINPUT */
154177
_pg_last_keydown_event = event;
178+
#endif /* WIN32 */
155179
}
156180
else if (type == SDL_TEXTINPUT) {
157181
if (_pg_last_keydown_event != NULL) {

0 commit comments

Comments
 (0)