[ltp] acpi_fakekey and sleep button

David Abrahams linux-thinkpad@linux-thinkpad.org
Wed, 11 Oct 2006 23:00:18 -0400


--=-=-=


Hi,

I can suspend to ram just fine by pressing Fn-F4, but
gnome-power-manager's suspend function doesn't work.  I'd like to make
GPM do what Fn-F4 does but the problem is that all I know about Fn-F4
is that it invokes

  #!/bin/bash
  . /usr/share/acpi-support/key-constants
  acpi_fakekey $KEY_SLEEP 

and I'm a little too inexperienced with Linux to understand the
implications of acpi_fakekey, whose (small) source is attached.  Can
anyone here help me track down where this event goes?

Thanks in advance,
Dave


--=-=-=
Content-Type: text/x-csrc
Content-Disposition: inline; filename=acpi_fakekey.c

#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <linux/input.h>

#define TestBit(bit, array) (array[(bit) / 8] & (1 << ((bit) % 8)))

int find_keyboard() {
	int i, j;
        int fd;
        char filename[32];
        char key_bitmask[(KEY_MAX + 7) / 8];

        for (i=0; i<32; i++) {
                snprintf(filename,sizeof(filename), "/dev/input/event%d", i);

                fd = open(filename, O_RDWR);
                ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bitmask)), key_bitmask);

		for (j = 0; j < BTN_MISC; j++) {
			if (TestBit(j, key_bitmask))
				break;
		}

                if (j < BTN_MISC) {
                        return fd;
                }
		close (fd);
        }
        return 0;
}

int main(int argc, char** argv) {
	int fd;
	int key;
	struct input_event event;

	if (argc == 2) {
		key = atoi(argv[1]);
	} else {
		return 1;
	}

	fd = find_keyboard();

	if (!fd) {
		return 2;
	}

	event.type = EV_KEY;
	event.code = key;
	event.value = 1;
	write(fd, &event, sizeof event);

	event.type = EV_KEY;
	event.code = key;
	event.value = 0;
	write(fd, &event, sizeof event);
	
	return 0;
}


--=-=-=


-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

--=-=-=--