-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcuepie.c
More file actions
69 lines (57 loc) · 1.45 KB
/
Copy pathcuepie.c
File metadata and controls
69 lines (57 loc) · 1.45 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <dirent.h>
#include <linux/input.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/select.h>
#include <sys/time.h>
#include <termios.h>
#include <signal.h>
int mkeycodes[12] = { 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
void handler (int sig)
{
fprintf (stderr, "\nexiting...(%d)\n", sig);
exit (0);
}
void perror_exit (char *error)
{
perror (error);
handler (9);
}
int main (int argc, char *argv[])
{
struct input_event ev[64];
int fd, rd, value, size = sizeof (struct input_event);
char name[256] = "Unknown";
char *device = NULL;
//Setup check
if (argv[1] == NULL){
device = "/dev/input/event0";
}
if ((getuid ()) != 0)
fprintf (stderr, "You are not root! This may not work...\n");
if (argc > 1)
device = argv[1];
//Open Device
if ((fd = open (device, O_RDONLY)) == -1)
fprintf (stderr, "%s is not a vaild device.\n", device);
while (1){
if ((rd = read (fd, ev, size * 64)) < size)
perror_exit ("read()");
value = ev[0].value;
if (value != ' ' && ev[1].value == 1 && ev[1].type == 1 ){ // Only read the key press event
if (ev[1].code != 28 ){
fprintf (stdout, "%d", (mkeycodes[(ev[1].code)]));
} else {
fprintf (stdout, "\n");
fflush (stdout);
}
}
}
return 0;
}