Skip to content

Instantly share code, notes, and snippets.

@eromatiya
Last active January 7, 2021 00:27
Show Gist options
  • Save eromatiya/fd9a12b3fc5abf7c1a4b4bd8fd498984 to your computer and use it in GitHub Desktop.
Save eromatiya/fd9a12b3fc5abf7c1a4b4bd8fd498984 to your computer and use it in GitHub Desktop.
Check CapsLock Status Programatically in Linux
#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