我想通过某种方式知道Capslock是否处于活动状态,认为我可以使用xet ,使用管道,通过popen('xset -q | grep Capslock')我能够找到,但我想要一些方法在没有使用命令的情况下,在C程序中,有没有办法知道这一点。 还有一件事我想在这个上下文中问一下, xset dons不能在linux的控制台模式下工作,我做alt + ctrl + f1然后登录那里如果尝试运行xset -q这会抛出错误,也许这可以'在控制台中与XWindows进行通信,因此对于这种情况可以采用什么解决方案。
I want some way to know if the Capslock is active or not, thought I can use xet for this purpose, using pipe, by popen('xset -q | grep Capslock') I am able to find out, but I want some way by which there is no use of the commands, in the C program, is there any way to know this. One more thing I want to ask in this context, xset doens't work in the console mode in linux, I do alt+ctrl+f1 then login there and if try to run xset -q this will throw error, perhaps this can't communicate with the XWindows in console, so what solution can be for this case.
最满意答案
我想知道Capslock是否有效
你可能想要XkbGetIndicatorState 。 例如:
#include <stdio.h> #include <stdlib.h> #include <X11/XKBlib.h> /* Compile this with -lX11 */ int main () { Display *display; Status status; unsigned state; display = XOpenDisplay (getenv ("DISPLAY")); if (!display) return 1; if (XkbGetIndicatorState (display, XkbUseCoreKbd, &state) != Success) return 2; printf ("Caps Lock is %s\n", (state & 1) ? "on" : "off"); return 0; }或者,您可以使用xset中使用的相同方法并使用XkbGetNamedIndicator ,这是一个更通用的功能。
I want some way to know if the Capslock is active or not
You probably want XkbGetIndicatorState. For instance:
#include <stdio.h> #include <stdlib.h> #include <X11/XKBlib.h> /* Compile this with -lX11 */ int main () { Display *display; Status status; unsigned state; display = XOpenDisplay (getenv ("DISPLAY")); if (!display) return 1; if (XkbGetIndicatorState (display, XkbUseCoreKbd, &state) != Success) return 2; printf ("Caps Lock is %s\n", (state & 1) ? "on" : "off"); return 0; }Alternatively, you can go with the same approach that is used in xset and use XkbGetNamedIndicator which is a more general function.
更多推荐
发布评论