Search code examples
glfw

How to detect lowercase letters


How one can detect lowercase letters with glfw? I can detect uppercase letters. For example,

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

However, in the following code, nothing is printed out.

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

and this is the declaration of the function

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

Solution

  • Check if SHIFT key is pressed:

    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