Advertisement
Guest User

Untitled

a guest
Dec 20th, 2015
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <fcntl.h>
  4. #include <iostream>
  5. #include <unistd.h>
  6. #include <linux/input.h>
  7. #include <vector>
  8.  
  9. #define DEVICEFILE "/dev/input/by-id/usb-1d57_ad02-event-kbd"
  10.  
  11. int main() {
  12.     int fd;
  13.     struct input_event ie;
  14.     struct input_event prev;
  15.  
  16.     if ((fd = open(DEVICEFILE, O_RDONLY)) == -1) {
  17.         perror("opening device");
  18.         exit(EXIT_FAILURE);
  19.     }
  20.  
  21.     int needed_events[3] = {458976, 458978, 458759};
  22.  
  23.     int i = 0;
  24.     int hits = 0;
  25.     while (read(fd, &ie, sizeof(struct input_event))) {
  26.         for (int j = 0; j < sizeof(ie); j++) {
  27.             if (prev.type == ie.type && prev.code == ie.code && prev.value == ie.value) continue;
  28.             if (ie.type != 4 && ie.code != 4) continue;
  29.  
  30.             if (needed_events[i] == ie.value) {
  31.                 hits++;
  32.                 i++;
  33.             } else {
  34.                 hits = 0;
  35.                 i = 0;
  36.             }
  37.  
  38.             if (hits == 3) {
  39.                 std::cout << system("echo 1 > /home/efog/Temp/HIT");
  40.                 std::cout << "Exact hit!\n";
  41.  
  42.                 system("killall -9 slimlock");
  43.                 execl("/usr/sbin/killall", "killall", "-9", "slimlock", (char *) 0);
  44.             }
  45.  
  46.             prev = ie;
  47.         }
  48.  
  49.         printf("\n");
  50.     }
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement