Forked from eromatiya/check-capslock-status-linux.cpp
Created
January 7, 2021 00:27
-
-
Save TaylanTatli/2d2a6dd7944a7563dd3a8dd2229a1487 to your computer and use it in GitHub Desktop.
Check CapsLock Status Programatically in Linux
This file contains 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