[SOLVED] No KEYDOWN events being generated with Chinese input

The following does not emit any SDL_KEYDOWN events when a Chinese input method is selected.

  bool quitFlag = false;
  int i = 0;
  SDL_Event event;
  while (!quitFlag) {
    while (SDL_PollEvent(&event)) {
      switch (event.type) {
      case SDL_QUIT:
	quitFlag = true;
	break;
      case SDL_KEYDOWN:
	printf("%d: Keydown event\n", i);
	break;
      case SDL_TEXTINPUT:
	printf("%d: Text input event: %s\n", i, event.text.text);
	break;
      }
    }
    i++;
  }

There is no preceding SDL_StartTextInput, and the full code is here Paste.ee - Basic SDL event capturer
I am on debian 11 and using ibus. I’m also unable to test this on another platform at the moment.
Is this intended behavior? It seems strange to me as it would make it impossible for people using CJK input methods to interact with programs without toggling input methods.

After a bit more fiddling I’ve realized that this happens because SDL starts with text input mode on, and adding a SDL_StopTextInput call before the loop makes it behave as expected.

  SDL_StopTextInput();
  bool quitFlag = false;
  bool toggle = false;
  int i = 0;
  SDL_Event event;
  while (!quitFlag) {
    while (SDL_PollEvent(&event)) {
      switch (event.type) {
      case SDL_QUIT:
        quitFlag = true;
        break;
      case SDL_KEYDOWN:
        if (event.key.keysym.sym == SDLK_ESCAPE) {
          if (toggle) {
            printf("Stopping text input\n");
            SDL_StopTextInput();
          } else {
            printf("Starting text input\n");
            SDL_StartTextInput();
          }
          toggle = !toggle;
        }
        printf("%d: Keydown event\n", i);
        break;
      case SDL_TEXTINPUT:
        printf("%d: Text input event: %s\n", i, event.text.text);
        break;
      }
    }
    i++;
  }
1 Like

I’m having to call StopTextInput at the start of my app for other reasons. I still question the sense of having this enabled by default - it seems to cause issues.