wok diff acpid/stuff/acpi_fakekey.c @ rev 2990

Up linux (2.6.29.3)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon May 11 19:08:50 2009 +0200 (2009-05-11)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/acpid/stuff/acpi_fakekey.c	Mon May 11 19:08:50 2009 +0200
     1.3 @@ -0,0 +1,64 @@
     1.4 +#include <unistd.h>
     1.5 +#include <fcntl.h>
     1.6 +#include <string.h>
     1.7 +#include <stdlib.h>
     1.8 +#include <stdio.h>
     1.9 +#include <linux/input.h>
    1.10 +
    1.11 +#define TestBit(bit, array) (array[(bit) / 8] & (1 << ((bit) % 8)))
    1.12 +
    1.13 +int find_keyboard() {
    1.14 +	int i, j;
    1.15 +        int fd;
    1.16 +        char filename[32];
    1.17 +        char key_bitmask[(KEY_MAX + 7) / 8];
    1.18 +
    1.19 +        for (i=0; i<32; i++) {
    1.20 +                snprintf(filename,sizeof(filename), "/dev/input/event%d", i);
    1.21 +
    1.22 +                fd = open(filename, O_RDWR);
    1.23 +                ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bitmask)), key_bitmask);
    1.24 +
    1.25 +		for (j = 0; j < BTN_MISC; j++) {
    1.26 +			if (TestBit(j, key_bitmask))
    1.27 +				break;
    1.28 +		}
    1.29 +
    1.30 +                if (j < BTN_MISC) {
    1.31 +                        return fd;
    1.32 +                }
    1.33 +		close (fd);
    1.34 +        }
    1.35 +        return 0;
    1.36 +}
    1.37 +
    1.38 +int main(int argc, char** argv) {
    1.39 +	int fd;
    1.40 +	int key;
    1.41 +	struct input_event event;
    1.42 +
    1.43 +	if (argc == 2) {
    1.44 +		key = atoi(argv[1]);
    1.45 +	} else {
    1.46 +		return 1;
    1.47 +	}
    1.48 +
    1.49 +	fd = find_keyboard();
    1.50 +
    1.51 +	if (!fd) {
    1.52 +		return 2;
    1.53 +	}
    1.54 +
    1.55 +	event.type = EV_KEY;
    1.56 +	event.code = key;
    1.57 +	event.value = 1;
    1.58 +	write(fd, &event, sizeof event);
    1.59 +
    1.60 +	event.type = EV_KEY;
    1.61 +	event.code = key;
    1.62 +	event.value = 0;
    1.63 +	write(fd, &event, sizeof event);
    1.64 +	
    1.65 +	return 0;
    1.66 +}
    1.67 +