使用 GetKeyState(VK_CAPITAL) & 1 在 Linux 中

发布于 2024-12-28 20:44:47 字数 301 浏览 4 评论 0原文

#include <windows.h>

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

但仅限于 Windows 如何

在 Linux 中使用 gcc 执行此操作?

什么是& 1GetKeyState(VK_CAPITAL) & 1 ?

#include <windows.h>

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

but limited to windows only

how to do this in linux with gcc ?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦在夏天 2025-01-04 20:44:47

对于基于 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文