-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patha.c
57 lines (53 loc) · 1.33 KB
/
a.c
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
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <libevdev/libevdev.h>
#include <stddef.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
struct libevdev *dev = NULL;
int fd;
int rc = 1;
fd = open("/dev/input/event2", O_RDONLY|O_NONBLOCK);
rc = libevdev_new_from_fd(fd, &dev);
if (rc < 0) {
fprintf(stderr, "Failed to init libevdev (%s)\n", strerror(-rc));
exit(1);
}
printf("Input device name: \"%s\"\n", libevdev_get_name(dev));
printf("Input device ID: bus %#x vendor %#x product %#x\n",
libevdev_get_id_bustype(dev),
libevdev_get_id_vendor(dev),
libevdev_get_id_product(dev));
do {
struct input_event ev;
rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev);
if (rc == 0) {
if (ev.type == EV_KEY) {
if (ev.value) {
switch (ev.code) {
case BTN_TR2:
printf("VOl up\n");
system("/usr/bin/amixer set Playback 5+");
break;
case BTN_TL2:
printf("VOl down\n");
system("/usr/bin/amixer set Playback 5-");
break;
default:
;
/* printf("Event: %s %s %d\n", */
/* libevdev_event_type_get_name(ev.type), */
/* libevdev_event_code_get_name(ev.type, ev.code), */
/* ev.value); */
}
}
}
}
} while (rc == 1 || rc == 0 || rc == -EAGAIN);
return 0;
}