在 Linux 中使用 GetKeyState(VK_CAPITAL) & 1

2023-12-13

#include <windows.h>

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

但仅限于Windows

如何在 Linux 中使用 gcc 做到这一点?

what is & 1 in GetKeyState(VK_CAPITAL) & 1 ?


对于基于 X11 的桌面的最常见情况:

#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");
    }
}

确保您有 X11 开发标头并使用以下命令进行编译:

$ gcc -lX11 test.c -o test

从桌面上的控制台窗口运行它:

$ ./test
caps off
$ ./test
caps on
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Linux 中使用 GetKeyState(VK_CAPITAL) & 1 的相关文章

随机推荐