-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
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
What is a correct way to handle keyboard input for active/current/selected/focused window only? #5979
Comments
Try using IsWindowFocused(). PS: GetKeyIndex() is a no-op since 1.87 |
Thanks. It did the job. I cannot believe I have overlooked it. I see that I do not need to put my keyboard handling code after all children to use ImGuiFocusedFlags_ChildWindows flag. I.e. I have |
I have another question. I have the following situation: processAAAInput does not handle input (arrow keys) unless I click inside the AAA window (I click the BBB child). Then it works until I press the CCC button. To make it to work again I need to click inside AAA again. P.S. Sorry, the source code tag in this message does not work for me -- it draws everything in one line here. |
Your source code is hard to decipher. Please make an effort to create an actual minimal pastable repro, and use eg ImGui::Text() elements to visuable the state of eg IsWindowFocused() return value. |
Please, never mind my last question. I never knew the focus is on the last Begin(…) window as far as I had common key handling (without a IsWindowFocused call). So, when I added IsWindowFocused my “main” window the one I drawn first did not handled any input until I clicked it. And I have left some key handlers in a child window so when I pressed the button outside it stopped working too until clicking inside. |
Great to hear. Closing as answered. |
Hello,
From imgui.h:
#define IMGUI_VERSION "1.89 WIP"
#define IMGUI_VERSION_NUM 18814
#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx))
#define IMGUI_HAS_TABLE
#define IMGUI_HAS_VIEWPORT // Viewport WIP branch
#define IMGUI_HAS_DOCK // Docking WIP branch
Dx12
What is a correct way to handle keyboard input for active/current/selected/focused window only? I.e. the window in the docking environment that is highlighted at this very moment. I have two windows that handle arrow keys differently. I tried:
if (ImGui::IsItemFocused()) { if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_UpArrow))) { ...
And
if (ImGui::IsItemActive ()) { if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_UpArrow))) { ...
It did not work. IsItemActive worked if I held the key and clicked the window caption. So, it was bad idea indeed.
I tried the code above within Begin/End. Sorry, I was unable to find a proper example.
Thank you.
The text was updated successfully, but these errors were encountered: