wok-stable view acpid/stuff/acpi_fakekey.c @ rev 10231
Add mm-common. Needed for new libxml++.
author | Christopher Rogers <slaxemulator@gmail.com> |
---|---|
date | Sat May 21 00:27:17 2011 +0000 (2011-05-21) |
parents | |
children |
line source
1 #include <unistd.h>
2 #include <fcntl.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <linux/input.h>
8 #define TestBit(bit, array) (array[(bit) / 8] & (1 << ((bit) % 8)))
10 int find_keyboard() {
11 int i, j;
12 int fd;
13 char filename[32];
14 char key_bitmask[(KEY_MAX + 7) / 8];
16 for (i=0; i<32; i++) {
17 snprintf(filename,sizeof(filename), "/dev/input/event%d", i);
19 fd = open(filename, O_RDWR);
20 ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bitmask)), key_bitmask);
22 for (j = 0; j < BTN_MISC; j++) {
23 if (TestBit(j, key_bitmask))
24 break;
25 }
27 if (j < BTN_MISC) {
28 return fd;
29 }
30 close (fd);
31 }
32 return 0;
33 }
35 int main(int argc, char** argv) {
36 int fd;
37 int key;
38 struct input_event event;
40 if (argc == 2) {
41 key = atoi(argv[1]);
42 } else {
43 return 1;
44 }
46 fd = find_keyboard();
48 if (!fd) {
49 return 2;
50 }
52 event.type = EV_KEY;
53 event.code = key;
54 event.value = 1;
55 write(fd, &event, sizeof event);
57 event.type = EV_KEY;
58 event.code = key;
59 event.value = 0;
60 write(fd, &event, sizeof event);
62 return 0;
63 }