Skip to content

Use ImGuiKey_Menu and Shift + F10 to invoke the context menu via keyboard - #9270

Closed
exelix11 wants to merge 1 commit into
ocornut:masterfrom
exelix11:master
Closed

Use ImGuiKey_Menu and Shift + F10 to invoke the context menu via keyboard#9270
exelix11 wants to merge 1 commit into
ocornut:masterfrom
exelix11:master

Conversation

@exelix11

@exelix11 exelix11 commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

I have been experimenting with this for better keyboard accessibility. I'd suggest allowing the use of ImGuiKey_Menu for this since that is the exact reason this key exists.

This issue was also was discussed in #8803 and it was mentioned that the windows convention for this is Shift + F10. I also implemented it as an alternative for keyboards that don't have ImGuiKey_Menu.

I'm not familiar enough with ImGui internals to know if this causes any issues so consider this mostly a draft to discuss potential issues or a better implementation

Most content in the demo window works with these changes, but there are a couple of issues still open:

  • Popups attached to non-selectable items can't be opened since the nav cursor can't highlight those UI components. Example:

    imgui/imgui_demo.cpp

    Lines 5412 to 5413 in ba84d2d

    ImGui::Text("(2) Or right-click this text");
    ImGui::OpenPopupOnItemClick("my popup", ImGuiPopupFlags_MouseButtonRight);
  • BeginPopupContextWindow opens the context menu near the mouse cursor rather than next to the nav cursor, this is not an issue but just an annoyance. One such example is the asset browser

    imgui/imgui_demo.cpp

    Lines 10996 to 10998 in ba84d2d

    if (ImGui::BeginPopupContextWindow())
    {
    ImGui::Text("Selection: %d items", Selection.Size);
  • What about items that have different popups depending on which button is pressed? I didn't find any such case in the demo window and I'd argue this is an anti-pattern since there is no meaningful way to make it keyboard-accessible. It's not something that should be encouraged.
  • Lots of code is repeated, maybe it needs an helper function to check for the keypresses?

@ocornut ocornut added nav keyboard/gamepad navigation popups inputs labels Mar 3, 2026
ocornut added a commit that referenced this pull request Mar 12, 2026
#8803, #9270)

This doesn't attempt to move the shortcut polling in NavUpdate() yet.
ocornut added a commit that referenced this pull request Mar 12, 2026
… with polling in NavUpdate(). (#8803, #9270)

This might be a little less flexible but removes burden from the higher-frequency calls.
ocornut added a commit that referenced this pull request Mar 12, 2026
…upContextItem() sequence aiming at title bar. (#8803, #9270)
@ocornut

ocornut commented Mar 12, 2026

Copy link
Copy Markdown
Owner

This is now merged with changes. See #8803 (comment) for details. Thank you!

@ocornut ocornut closed this Mar 12, 2026
ocornut pushed a commit that referenced this pull request Jun 24, 2026
…esting for _NavEnableKeyboard instead of _NavEnableGamepad. (#9454)

cc: #8803, #9270
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

inputs nav keyboard/gamepad navigation popups

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants