-
Notifications
You must be signed in to change notification settings - Fork 104
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
Numpad (keypad) inputs not working on the demos #114
Comments
Appreciate the reply! Yeah, I agree that the issue is os/backend dependent. I also had to borrow the keyboard of my's son gaming PC to test this. I tested it on both Mac and Linux. On Mac, num lock was not recognized, so it worked as if the num lock is always on (on: number inputs, off: arrow and other control inputs), but at least number inputs from the keypad worked. On Linux, both num lock on & off worked as expected. Maybe the Windows keyboard is not properly recognized for Mac? Here I'm talking about in general applications. ImGui Manual demo didn't work with the keypad at all on both platforms. But, https://jnmaloney.github.io/WebGui/imgui.html worked like other application on each platform. My understanding is that it uses GLFW backend while ImGui Manual (and imgui_bundle when built for web) uses SDL2. So my guess is the issue lies in the SDL2 backend. One hack I found out is adding the following code at https://github.com/pthom/imgui/blob/master/backends/imgui_impl_sdl2.cpp#L357: if (event->type == SDL_KEYDOWN) {
if (ImGuiKey_Keypad0 <= key && key <= ImGuiKey_Keypad9) {
const char c = '0' + (char)(key - ImGuiKey_Keypad0);
io.AddInputCharactersUTF8((const char*)&c);
} else if (key == ImGuiKey_KeypadDecimal) {
const char c = '.';
io.AddInputCharactersUTF8((const char*)&c);
}
} Then at least number inputs worked even though the num lock mode is being ignored (regarded as always on.) Maybe there is also a way to check whether the num lock is on or off and forward control inputs instead when it's off... Anyhow this felt like a hack and I didn't pursue further. I was aware the ImGui's IO event API changes, but https://jnmaloney.github.io/WebGui/imgui.html worked as I noted and it's using 1.89.5, which seems to have the changes. I already tried tools/Metric&Debugger/Inputs. It showed proper recognitions of keypad inputs, but it still not worked in ImGui Manual demo. For instance, when I press Keypad 1 on Linux (either num lock on or off), it showed: For the word wrapping, I just patched ocornut/imgui#3237 (comment). It's not perfect, but good enough for my use cases. |
Nothing happens if you try typing a digit in any input field with numpad keys. My web app based on
hello_imgui
has the same issue. And I note that it happens on the demos linked in this repo's readme, too, except the calculator one, which I think doing some manual key input handling.Not sure if the issue is platform-specific (emscripten+sdl2, I believe) or not. I tried to figure out the cause and spent a few hours this morning looking into the relevant code, but no luck so far.
Another demo of yours (https://github.com/pthom/implot_demo) somehow works with numpad keys, so I wonder what's the difference. It doesn't works 100% though. With Num Lock on, it works. But with Num Lock off, nothing happens (in other words, pressing the keypad 4 doesn't work like the left arrow key.) Another ImGui demo that doesn't use SDL2 (https://jnmaloney.github.io/WebGui/imgui.html) works perfectly with numpad keys for both Num Lock on and off.
I would appreciate any insight on how this can be fixed or any workaround.
The text was updated successfully, but these errors were encountered: