Imgui: ImGui::IsKeyPressed('a') vs ImGui::IsKeyPressed('A')

Created on 27 May 2017  路  2Comments  路  Source: ocornut/imgui

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];
}

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).

All 2 comments

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).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bogdaNNNN1 picture bogdaNNNN1  路  3Comments

inflex picture inflex  路  3Comments

bizehao picture bizehao  路  3Comments

NPatch picture NPatch  路  3Comments

namuda picture namuda  路  3Comments