Silk.NET icon indicating copy to clipboard operation
Silk.NET copied to clipboard

Silk.NET.OpenGL.Extensions.ImGui: Key mod not sent to ImGui IO

Open tvardero opened this issue 2 months ago • 1 comments

Summary

Key mods like Ctrl, Alt, Shift are not sent to ImGUI during imguiController.Update((float)delta);

Steps to reproduce

Reproducible here: https://github.com/dotnet/Silk.NET/tree/main/examples/CSharp/OpenGL%20Demos Windows 11, using WindowOptions.Default

  1. Add ImGui.ShowDemoWindow(); before imguiController.Render(); to draw demo window
  2. Start the project
  3. In demo window, navigate to "Inputs & Focus" category
  4. Press "Ctrl", "Ctrl+A", "Shift+Tab" or any other key combo with mod keys

Expected: Mods should appear in "Keys mods:" label. "Keys down:" label should show "ModCtrl", "ModShift", etc... together with "LeftCtrl", "LeftShift", etc...

Actual: Mods do not appear in "Keys mods:" label. "Keys down:" label contains only "LeftCtrl", "LeftShift", etc... This results in shortcuts not working at all. You can test shortcuts in "Shortcuts" subcategory of "Inputs & Focus"

Comments

Issue is somewhere here https://github.com/dotnet/Silk.NET/blob/3c0313b2d69bbde12224c759a76bc2e7e064a893/src/OpenGL/Extensions/Silk.NET.OpenGL.Extensions.ImGui/ImGuiController.cs#L250

tvardero avatar Nov 15 '25 22:11 tvardero

Current workaround:

// Add this after imGuiController.Update((float)delta);
var io = ImGui.GetIO();
var keyboard = input.Keyboards[0];

io.AddKeyEvent(ImGuiKey.ModAlt, keyboard.IsKeyPressed(Key.AltLeft) || keyboard.IsKeyPressed(Key.AltRight));
io.AddKeyEvent(ImGuiKey.ModSuper, keyboard.IsKeyPressed(Key.SuperLeft) || keyboard.IsKeyPressed(Key.SuperRight));
io.AddKeyEvent(ImGuiKey.ModCtrl, keyboard.IsKeyPressed(Key.ControlLeft) || keyboard.IsKeyPressed(Key.ControlRight));
io.AddKeyEvent(ImGuiKey.ModShift, keyboard.IsKeyPressed(Key.ShiftLeft) || keyboard.IsKeyPressed(Key.ShiftRight));

Related: https://github.com/ocornut/imgui/issues/5047

tvardero avatar Nov 15 '25 23:11 tvardero