如何检测小写字母

How to detect lowercase letters

如何使用 glfw 检测小写字母?我可以检测大写字母。例如,

if ( key == 'A' && action == GLFW_PRESS )
        std::cout << (char)key <<std::endl;

但是,在下面的代码中,什么也没有打印出来。

if ( key == 'a' && action == GLFW_PRESS )
        std::cout << (char)key <<std::endl;

这是函数的声明

void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode);

检查是否按下了SHIFT键:

if ( key == GLFW_KEY_A && action == GLFW_PRESS ) {
    if (mode == GLFW_MOD_SHIFT) {
      //uppercase
    }
    else {
      //lowercase
    }
}

http://www.glfw.org/docs/latest/group__mods.html

刚遇到同样的问题,最终我发现对于角色最好这样做:

// Set the call back to the Char value pressed
glfwSetCharCallback(window, character_callback);

你的回电应该是这样的:

void character_callback(GLFWwindow* window, unsigned int codepoint) {
    if (codepoint == 'g') {
        // No need to check all combinations of RIGHT_SHIFT, LEFT_SHIFT, CAPS_LOCK
        std::cout << "lower case g pressed" << std::endl;
    }
}

您可以在 GLFW 输入指南中找到更多相关信息:https://www.glfw.org/docs/3.3/input_guide.html

希望这对遇到这个问题的人有所帮助,祝周末愉快。 谢谢,