using GetKeyState(VK_CAPITAL) & 1 in linux

后端 未结 1 1746
感动是毒
感动是毒 2021-01-14 05:02
#include 

int main() {
if ( !GetKeyState(VK_CAPITAL) & 1 ) {
printf(\"caps off\");
}
else
printf(\"caps on\");
return 0;
}

bu

相关标签:
1条回答
  • 2021-01-14 05:54

    For the most common case of an X11-based desktop:

    #include <stdio.h>
    #include <X11/XKBlib.h>
    
    int main() {
        Display * d = XOpenDisplay((char*)0);
    
        if (d) {
            unsigned n;
    
            XkbGetIndicatorState(d, XkbUseCoreKbd, &n);
    
            printf((n & 1)?"caps on\n":"caps off\n");
        }
    }
    

    Make sure you have the X11 development headers and compile with:

    $ gcc -lX11 test.c -o test
    

    Run it from a console window in your desktop:

    $ ./test
    caps off
    $ ./test
    caps on
    
    0 讨论(0)
提交回复
热议问题