Skip to content

How to use IsKeyPressed(ImGuiKey key) with imgui v1.87.3 #309

Description

@pixtur

Hi,

I'm trying to port from 1.86 to 1.87.3 and got stuck with the following change:

IsKeyPressed(int key)
IsKeyPressed(ImGuiKey key)

In our software we have defined a windows compatible enum that is obviously incompatible with the enum defined in ImGuiKey.cs. So casting to an int like I did before is no longer an option:

if (ImGui.IsKeyPressed((int)Key.Esc))) { 
     // some something
}

Our key handler is currently implemented like this:

   var form = new ImGuiDx11RenderForm(windowTitle)
                             {
                                 ClientSize = new Size(640, 480),
                                 Icon = new Icon(@"Resources\t3\t3.ico", 48, 48)
                             };
    form.KeyDown += HandleKeyDown;
    form.KeyUp += HandleKeyUp;
        private static void HandleKeyDown(object sender, KeyEventArgs e)
        {
            var keyIndex = (int)e.KeyCode;
            if (keyIndex >= Core.IO.KeyHandler.PressedKeys.Length)
            {
                Log.Warning($"Ignoring out of range key code {e.KeyCode} with index {keyIndex}");
            }
            else
            {
                Core.IO.KeyHandler.PressedKeys[keyIndex] = true;
            }
        }

        private static void HandleKeyUp(object sender, KeyEventArgs e)
        {
            var keyIndex = (int)e.KeyCode;
            if (keyIndex < Core.IO.KeyHandler.PressedKeys.Length)
            {
                Core.IO.KeyHandler.PressedKeys[keyIndex] = false;
            }
        }

I would be very grateful for any pointers or advice what would be a good approach to adjust our implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions