How can I get the keyboard state in Linux?

前端 未结 4 629
遥遥无期
遥遥无期 2020-12-02 14:01

I want to check if the user pressed down the Shift key when the program starts. (That means, press down the Shift key before the program is started) It\'s

4条回答
  •  青春惊慌失措
    2020-12-02 14:32

    I have found a very simple way through gtk/gdk.

    int main ( int argc, char *argv[], char *env[] )
    {
        gtk_init(&argc, &argv);
    
        GdkModifierType button_state;
        gdk_window_get_pointer(NULL, NULL, NULL, &button_state);
        if(button_state & GDK_CONTROL_MASK) {
            printf("ctrl key is pressed");
        }
    }
    

提交回复
热议问题