summarylogtreecommitdiffstats
path: root/shift-not-pressed.c
diff options
context:
space:
mode:
authorsharethewisdom2019-06-10 11:40:26 +0200
committersharethewisdom2019-06-10 11:49:36 +0200
commitd5598c1e61e07d9fbe0c8360ee9e9f11f6bd6b2b (patch)
treeb81fa004ab53be74d028f9aa898bb6f2dd471496 /shift-not-pressed.c
parent41d2f8aeea4a9548a8208dd53519bb8dc7fc3ed1 (diff)
downloadaur-shift-not-pressed.tar.gz
changed the pkg name, added help option and corrected exit codes
Diffstat (limited to 'shift-not-pressed.c')
-rw-r--r--shift-not-pressed.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/shift-not-pressed.c b/shift-not-pressed.c
new file mode 100644
index 000000000000..3493140a188f
--- /dev/null
+++ b/shift-not-pressed.c
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <getopt.h>
+#include <string.h>
+#include <strings.h>
+
+int main(int argc, char **argv)
+{
+ char shift_state;
+ const char* usage =
+ "Usage: shift-not-pressed [--help]\n\n"
+ "exit codes:\n"
+ " 0 (succes) shift was not pressed\n"
+ " 1 (succes) shift was pressed\n"
+ " 2 (fail) could not get shift state\n";
+
+ static struct option lopts[] = {
+ {"help", no_argument, NULL, 'h'}
+ };
+ int c;
+ while (1) {
+ int opti;
+ c = getopt_long(argc, argv, "h", lopts, &opti);
+ if (c == -1) {
+ break;
+ }
+ switch (c) {
+ case 'h': fprintf(stdout, "%s", usage);
+ exit(0);
+ break;
+ default: break;
+ }
+ }
+
+ shift_state = 6;
+ if (ioctl(0, TIOCLINUX, &shift_state) < 0) {
+ perror("ioctl TIOCLINUX 6 (get shift state)");
+ exit(2);
+ }
+ exit(shift_state);
+}