Skip to content

Instantly share code, notes, and snippets.

@meoso
Last active February 3, 2020 04:28
Show Gist options
  • Save meoso/b46b441b31344804c6837829e059c2b8 to your computer and use it in GitHub Desktop.
Save meoso/b46b441b31344804c6837829e059c2b8 to your computer and use it in GitHub Desktop.
linux keyboard return shift-key pressed state
#include <sys/ioctl.h>
#include <asm/ioctls.h>
#include <stdio.h>
#include <fcntl.h>
// code by "dma" via https://forums.gentoo.org/viewtopic-p-2455159.html#2455159
int main(int argc, char *argv[]) {
int fd;
char shift_state;
fd = open("/dev/console", O_RDWR);
/*
* From console_ioctl:
* TIOCLINUX, subcode=6
* argp points to a char which is set to the value of the kernel
* variable shift_state. (Since 1.1.32.)
*/
shift_state = 6;
ioctl(fd, TIOCLINUX, &shift_state);
printf("shift_state = %i\n", (int)shift_state);
close(fd);
return shift_state;
}
#!/bin/bash
shift_state=$(sudo ~/path/to/shift_state)
if (( $shift_state )) ; then
echo "shift-key active"
else
echo "shift-key not active"
fi
@meoso
Copy link
Author

meoso commented May 1, 2017

sudo visudo

username ALL=(ALL) NOPASSWD: /path/to/shift_state

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment