Last active
January 7, 2021 00:27
-
-
Save eromatiya/fd9a12b3fc5abf7c1a4b4bd8fd498984 to your computer and use it in GitHub Desktop.
Check CapsLock Status Programatically in Linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} | |
/* compile with `g++ -o capschecker capscheck.cpp -lX11` */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment