ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
60.22k stars 10.2k forks source link

Android Key handling issue #2838

Closed Skarpeys closed 4 years ago

Skarpeys commented 5 years ago

Phone: Xperia Z5 Premium Android: 7.1.1 ImGui: 1.69 zmertens GitHub (come with Android example, I tried 1.74 with zmertens android example but it won't compile) SDL: 2.0.9 NDK Target Build: Android26, GLES3 3.0

I didn't make any code for keyboard implement beside had SDL_StartTextInput() for Android Virtual Keyboard to shown up.

Xperia Keyboard (default) | Swift Keyboard: Inside ImGui::InputText - all keys work fine but Backspace key. It will get auto repeat - and then stuck at always auto repeat backspace <~~ mean can't type in anything else, even when change to another InputText, all char will be removed.

Gboard (Google Keyboard) & GoTiengViet Keyboard (Vietnamese): Backspace not even works, nothing happens after tap it. But if hold it for a while (about 5 sec), will get 1 char removed (1 backspace key happens)

I'm not sure if this issue is from ImGui or stb_input or SDL, or Android or zmertens Android port. I think it's from SDL, but I'm so desperated, so I post it here.

P/S:

ocornut commented 5 years ago

You should try to log the SDL events and narrow down the problem, probably an SDL problems.

Do you have the same problem with Arrow keys? Asking because Backspace is handled like a Key wheras text is handled like Character (they are different input concept).

Skarpeys commented 5 years ago

Yep, same problem with Arrow keys (nothing happens). I also tried a Bluetooth Keyboard, same issue as Virtual Keyboard.

ocornut commented 4 years ago

You should try to log/print the SDL events coming in the app and debug it from there.

Skarpeys commented 4 years ago

Trying that ... I tried a sample SDL Android app alone to test its input and it works fine. This issue is not from SDL.

P/S: even stranger behavior: Backspace key from Virtual Keyboard from Android Virtual Device doesn't work at all, but physical Keyboard gets that "forever auto repeat". (AVD by default only gives GLES 2.0 for graphic option. I didn't notice this, that's why it got black screen at run. Fixed this and I face this behavior)

Skarpeys commented 4 years ago

It IS from SDL. SDL_KEYUP event never get trigger for Backspace physical key on Android (Windows works fine). This explains "forever auto repeat" since:

// imgui_impl_sdl.cpp, line 111 _case SDL_KEYUP: ...... io.KeysDown[key] = (event->type == SDLKEYDOWN);

will be always "true" for physical Backspace.

To this point, it's got nothing to do with ImGui. Still, there is "nothing happens" when try Virtual Keyboard. From log, it does recognize Virtual Backspace (including SDL_KEYUP event).

P/S: I only have about 1 hour each day for this, will update later.

Skarpeys commented 4 years ago

Got it, still from SDL. SDL Virtual Backspace gets SDL_KEYUP right after SDL_KEYDOWN (Android only), even when we don't release the Virtual Backspace.

static bool triggered = false;
if (event->type == SDL_KEYDOWN && e.key.keysym.scancode == SDL_SCANCODE_BACKSPACE) {
  DoFunction1();
  triggered = true;
}

if (event->type == SDL_KEYUP && e.key.keysym.scancode == SDL_SCANCODE_BACKSPACE) {
  DoFunction2();
  triggered = false;
}

if (triggered) {
  DoFunction3();
}

DoFunction1 & DoFunction2 work fine but DoFunction3 never gets called ~~> ImGui doesn't have any chance to do anything.

Case closed, this has nothing to do with ImGui. I will try to report to SDL later.