summarylogtreecommitdiffstats
path: root/shift-not-pressed.c
blob: 3493140a188f6cb82d3460fcb62f316d0c9d6cd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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);
}