使用函数GetKeyState(VK_CAPITAL)及1在Linux [英] using GetKeyState(VK_CAPITAL) & 1 in linux

查看:1515
本文介绍了使用函数GetKeyState(VK_CAPITAL)及1在Linux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <windows.h>

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

但不限于仅适用于Windows

but limited to windows only

如何使用gcc为此在Linux呢?

how to do this in linux with gcc ?

什么&安培; 1 函数GetKeyState(VK_CAPITAL)及1

推荐答案

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

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

请确保您有X11开发的头文件和编译:

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

这篇关于使用函数GetKeyState(VK_CAPITAL)及1在Linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆