Last active
February 3, 2020 04:28
-
-
Save meoso/b46b441b31344804c6837829e059c2b8 to your computer and use it in GitHub Desktop.
linux keyboard return shift-key pressed state
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 <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; | |
} |
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
#!/bin/bash | |
shift_state=$(sudo ~/path/to/shift_state) | |
if (( $shift_state )) ; then | |
echo "shift-key active" | |
else | |
echo "shift-key not active" | |
fi |
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