-
-
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
Remapping keyboard input to gamepad for navigation #7115
Comments
(For completeness, please note that In principle you can use this logic to remap, so you would e.g. transform But there's a slight issue in your case: you can transform your events into corresponding keyboard nav events. But handling gamepad nav events is currently conditioned by // Start the Dear ImGui frame
const int input_queue_size_before = ImGui::GetCurrentContext()->InputEventsQueue.Size; // record event count before backend submit them
ImGui_ImplDX11_NewFrame();
ImGui_ImplWin32_NewFrame();
// Call between backend and main lib NewFrame():
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
YourFunctionToRemapInput(input_queue_size_before);
ImGui::NewFrame(); However, doing so would only make your app work with you specific gamepad. If you only need your app your work with that setup it may be fine, but otherwise I would instead be looking for a third-party app to do remapping on selected apps. |
Thanks for the quick response - I wasn't aware that AddKeyEvent could be used with other values than Using |
Your code is essentially copying keys but it will do so with an extra frame of lag so that's not ideal. |
Version/Branch of Dear ImGui:
Version: 1.90
Branch: Checked-out tag v1.90
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_win32.cpp + imgui_impl_dx11.cpp
Compiler: MSVC, C++20
Operating System: Windows 10
My Issue/Question:
I'm accepting input from a USB controller that presents as a keyboard but has directional keys. For example, pressing up,down,left,right on the controller sends the w,a,s,d keypresses. It also has a select key. I'd like to navigate ImGUI using only this controller (no standard USB keyboard, and no mouse).
I had understood from the examples in #787 that I could detect which keys are pressed (w,a,s,d), and generate a navigation event to pass to ImGui. I have done my best to implement that using the new APIs in #4921. I don't believe I need to use
io.SetKeyEventNativeData()
. Config flags includeNavEnableKeyboard
andNavEnableGamepad
. I also added:to main.cpp, but the flag shows as disabled in Configuration > Backend flags. I understand that this may be required to use AddKeyEvent, but I'm not sure how to ensure it is enabled.
Using the code below, I can press W,A,S,D on my standard USB keyboard (to emulate the controller) and see the down/up events being printed from std::cout. I can use the normal directional arrows to navigate ImGUI as expected, but when I press W,A,S,D, nothing happens.
Compiled in debug mode, confirmed that assertions are enabled.
Standalone, minimal, complete and verifiable example:
The text was updated successfully, but these errors were encountered: