#include

int main() {

if ( !GetKeyState(VK_CAPITAL) & 1 ) {

printf("caps off");

}

else

printf("caps on");

return 0;

}

但仅限于Windows

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

什么是& GetKeyState(VK_CAPITAL)中的1 1个

解决方法:

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

#include

#include

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

标签:gcc,capslock,c-3,linux

来源: https://codeday.me/bug/20191101/1986094.html

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐