TalonBraveInfo / OpenHoW

Open-source reimplementation of Gremlin's Hogs of War (PC/PSX).
http://talonbrave.info
GNU General Public License v3.0
166 stars 13 forks source link

Keyboard input fails upon hitting enter with ImGui open #70

Closed hogsy closed 5 years ago

hogsy commented 5 years ago

When entering text into a field, this works fine, however as soon as you hit enter it looks like ImGui gets locked into a stage of thinking the enter key is still pressed?

hogsy commented 5 years ago

See if you can spot the problem...

            case SDL_KEYUP:
            case SDL_KEYDOWN: {
                if(io.WantCaptureKeyboard) {
                    int key = event.key.keysym.scancode;
                    IM_ASSERT(key >= 0 && key < IM_ARRAYSIZE(io.KeysDown));
                    io.KeysDown[key] = (event.type == SDL_KEYDOWN);
                    io.KeyShift = ((SDL_GetModState() & KMOD_SHIFT) != 0);
                    io.KeyCtrl = ((SDL_GetModState() & KMOD_CTRL) != 0);
                    io.KeyAlt = ((SDL_GetModState() & KMOD_ALT) != 0);
                    io.KeySuper = ((SDL_GetModState() & KMOD_GUI) != 0);
                    break;
                }

                int key = TranslateSDLKey(event.key.keysym.sym);
                if(key != -1) {
                    Input_SetKeyState(key, (event.type == SDL_KEYDOWN));
                }
            } break;

No? User hits enter, key is up and ImGui no longer wants input - we never tell it that the key was released.

hogsy commented 5 years ago

Fixed