Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable Alt key to toggle Nav Menu Layer #3560

Closed
vexe opened this issue Oct 26, 2020 · 6 comments
Closed

Disable Alt key to toggle Nav Menu Layer #3560

vexe opened this issue Oct 26, 2020 · 6 comments
Labels
nav keyboard/gamepad navigation

Comments

@vexe
Copy link

vexe commented Oct 26, 2020

Version/Branch of Dear ImGui

Version: 1.79 WIP (17803)
Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_win32.cpp + imgui_impl_dx11.cpp
Compiler: MSVC
Operating System: Win7 64-bit & Win10 64-bit

My Issue/Question:

Is there any way to disable the "Press and release ALT to toggle menu behavior"? As I use ALT for commands in my text editor

The code I found relevant to this is this snippet:

// Keyboard: Press and Release ALT to toggle menu layer
    // FIXME: We lack an explicit IO variable for "is the imgui window focused", so compare mouse validity to detect the common case of back-end clearing releases all keys on ALT-TAB
    if (IsNavInputTest(ImGuiNavInput_KeyMenu_, ImGuiInputReadMode_Pressed))
        g.NavWindowingToggleLayer = true;
    if ((g.ActiveId == 0 || g.ActiveIdAllowOverlap) && g.NavWindowingToggleLayer && IsNavInputTest(ImGuiNavInput_KeyMenu_, ImGuiInputReadMode_Released))
        if (IsMousePosValid(&g.IO.MousePos) == IsMousePosValid(&g.IO.MousePosPrev))
            apply_toggle_layer = true;

Setting that apply_toggle_layer to false fixes my issue but ideally I don't want to touch any of this code.

Thanks for any pointers!

@ocornut ocornut changed the title Disable Disable Alt key to toggle Nav Menu Layer Oct 26, 2020
@ocornut ocornut added the nav keyboard/gamepad navigation label Oct 26, 2020
@roever
Copy link

roever commented Jan 24, 2021

This problem is even more pronounced with the German (and probably other) keyboard layouts. On the German layout several input characters are mapped to AltGr+other key, e.g. "[" is input using AltGr+8. When I use any text input widgets be them one line text input or editors, each time someone enters one of these symbols the focus jumps, making it very clunky to enter text containing these symbols.

I think that the proper solution would be to only do the menu action, when no other key has been pressed between down and up of the alt or altgr key.

@stormsc1
Copy link

stormsc1 commented Mar 11, 2021

Is there still no way of disabling this without changing ImGui itself?...

@pixtur
Copy link

pixtur commented Mar 13, 2021

I ran into the same issue, because I need to ALT for a snap modifier key while dragging controls. (SHIFT and CTRL are already used for other purposes). For me it's not a show stopper, though.

@kettek
Copy link

kettek commented Sep 25, 2021

Same issue over here, for use with additional cursor controls for a 3D map editor. Would be really nice to have this be optional.

@rokups
Copy link
Contributor

rokups commented Oct 18, 2021

As a temporary workaround, when your application handles ALT key you may set ImGui::GetCurrentContext()->NavWindowingToggleLayer = true; on that frame. This of course is a not supported solution and requires imgui_internal.h included, so expect it to break without prior notice.

UriMurcia added a commit to Horizons-Games/Axolotl-Engine that referenced this issue Feb 13, 2023
Based on the solution seen in ocornut/imgui#3560

Co-Authored-By: gerard-queralt <79362519+gerard-queralt@users.noreply.github.com>
@ocornut
Copy link
Owner

ocornut commented Mar 7, 2023

I have forgotten to post here when releasing 1.89 in November, as well as forgetting to tag this specific post in my myriad of commits related to input ownership system. But this should now be solved.

Many of the API are still in imgui_internal.h and therefore have no demo, but the demo_input_owner_and_routing branch has some demo for it, in particular this commit shows ways to hook ALT:
1e00a85

The variety of options and how they can be used are quite subtle and complex. Generally you need some form of conditional to not just steal the Alt mod key globally

But TL;DR; as per your statement above:

  • If you want to disable Alt while your text editor is active, you can call SetKeyOwner(ImGuiMod_Alt, id); in your widget code.
  • You may call SetItemKeyOwner(ImGuiMod_Alt) after submitting the widget which is roughly equivalent to if (IsItemHovered() || IsItemActive()) { SetKeyOwner(....); }.

If you want Alt to be conditionally disabled at the time of its press or hold you can also do that.

(Linking to #2637, #2620, #2891, #3370, #3724, #4828, #5108, #5242, #5641 for related features)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nav keyboard/gamepad navigation
Projects
None yet
Development

No branches or pull requests

7 participants