Hi all, I had some trouble switching from SDL2 to GLFW and it boiled down to this:
In SDL2 I did: ImGui::IsKeyPressed('a')
In GLFW I had to write: ImGui::IsKeyPressed('A')
If anybody needs it, I fixed the GLFW callback to work like SDL2, I don't know if that's the best approach tho:
void ImGui_ImplGlfwGL3_KeyCallback(GLFWwindow*, int key, int, int action, int mods)
{
// basically: when SHIFT isn't pressed but key is in A-Z range, add ascii offset to make it lower case
if (key >= 'A' && key <= 'Z' && !(mods & GLFW_MOD_SHIFT)) {
key += 'a' - 'A';
}
ImGuiIO& io = ImGui::GetIO();
if (action == GLFW_PRESS)
io.KeysDown[key] = true;
if (action == GLFW_RELEASE)
io.KeysDown[key] = false;
(void)mods; // Modifiers are not reliable across systems
io.KeyCtrl = io.KeysDown[GLFW_KEY_LEFT_CONTROL] || io.KeysDown[GLFW_KEY_RIGHT_CONTROL];
io.KeyShift = io.KeysDown[GLFW_KEY_LEFT_SHIFT] || io.KeysDown[GLFW_KEY_RIGHT_SHIFT];
io.KeyAlt = io.KeysDown[GLFW_KEY_LEFT_ALT] || io.KeysDown[GLFW_KEY_RIGHT_ALT];
io.KeySuper = io.KeysDown[GLFW_KEY_LEFT_SUPER] || io.KeysDown[GLFW_KEY_RIGHT_SUPER];
}
The keys order are decided and stored by your backend, so the indices are as such.
I have clarified the comments about that to make it clearer.
ImGui doesn't know about the meaning of every key (it will be required later as we introduce shortcuts).
Closing this as there's no open question.
(I hope it will work out ok to introduce full imgui-side enum in the future (perhaps with duplicate function calls or suggesting user to do full remapping prior to passing to io.? I don't know how it would work yet).
Most helpful comment
Closing this as there's no open question.
(I hope it will work out ok to introduce full imgui-side enum in the future (perhaps with duplicate function calls or suggesting user to do full remapping prior to passing to io.? I don't know how it would work yet).