Skip to content

Key Events have changed in ImGui #87

@jvannugteren

Description

@jvannugteren

In the latest version of ImGui the key events enums have shifted by 512 preventing proper capture of keys such as delete and backspace. Now the function "AddKeyEvent" has to be used to do the translation.

I think the issue can be fixed by replacing the switch in src/Magnum/ImGuiIntegration/Context.hpp file to:

switch(event.key()) {
        /* LCOV_EXCL_START */
        case KeyEvent::Key::LeftShift:
        case KeyEvent::Key::RightShift:
            io.KeyShift = value;
            break;
        case KeyEvent::Key::LeftCtrl:
        case KeyEvent::Key::RightCtrl:
            io.KeyCtrl = value;
            break;
        case KeyEvent::Key::LeftAlt:
        case KeyEvent::Key::RightAlt:
            io.KeyAlt = value;
            break;
        case KeyEvent::Key::LeftSuper:
        case KeyEvent::Key::RightSuper:
            io.KeySuper = value;
            break;
        case KeyEvent::Key::Tab:
            io.AddKeyEvent(ImGuiKey_Tab, value);
            break;
        case KeyEvent::Key::Up:
            io.AddKeyEvent(ImGuiKey_UpArrow, value);
            break;
        case KeyEvent::Key::Down:
            io.AddKeyEvent(ImGuiKey_DownArrow, value);
            break;
        case KeyEvent::Key::Left:
            io.AddKeyEvent(ImGuiKey_LeftArrow, value);
            break;
        case KeyEvent::Key::Right:
            io.AddKeyEvent(ImGuiKey_RightArrow, value);
            break;
        case KeyEvent::Key::Home:
            io.AddKeyEvent(ImGuiKey_Home, value);
            break;
        case KeyEvent::Key::End:
            io.AddKeyEvent(ImGuiKey_End, value);
            break;
        case KeyEvent::Key::PageUp:
            io.AddKeyEvent(ImGuiKey_PageUp, value);
            break;
        case KeyEvent::Key::PageDown:
            io.AddKeyEvent(ImGuiKey_PageDown, value);
            break;
        case KeyEvent::Key::Enter:
        case KeyEvent::Key::NumEnter:
            io.AddKeyEvent(ImGuiKey_Enter, value);
            break;
        case KeyEvent::Key::Esc:
            io.AddKeyEvent(ImGuiKey_Escape, value);
            break;
        case KeyEvent::Key::Space:
            io.AddKeyEvent(ImGuiKey_Space, value);
            break;
        case KeyEvent::Key::Backspace:
            io.AddKeyEvent(ImGuiKey_Backspace, value);
            break;
        case KeyEvent::Key::Delete:
            io.AddKeyEvent(ImGuiKey_Delete, value);
            break;
        case KeyEvent::Key::A:
            io.AddKeyEvent(ImGuiKey_A, value);
            break;
        case KeyEvent::Key::C:
            io.AddKeyEvent(ImGuiKey_C, value);
            break;
        case KeyEvent::Key::V:
            io.AddKeyEvent(ImGuiKey_V, value);
            break;
        case KeyEvent::Key::X:
            io.AddKeyEvent(ImGuiKey_X, value);
            break;
        case KeyEvent::Key::Y:
            io.AddKeyEvent(ImGuiKey_Y, value);
            break;
        case KeyEvent::Key::Z:
            io.AddKeyEvent(ImGuiKey_Z, value);
            break;
        /* LCOV_EXCL_STOP */

        /* Unknown key, do nothing */
        default: return false;
    }

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions