VineyardComputers-Wakeup

From richmondmakerlabs.uk
Jump to navigation Jump to search

N.B. This wiki needs a spring clean and the information on this page may be (considerably) out of date.

The requirement is to wake the computer from a sleep or power-saving mode when any keyboard key is pressed, but not to wake up when the mouse is moved. It's a Raspberry Pi running Raspian-Jessie, with LXDE-pi desktop. The sleep or power-saving mode is accomplished by the command xset dpms 0

One way to go about protecting wake-up from inadvertent mouse-moves is this: When the Pi is put into sleep mode, the mouse is disabled using an 'xinput' command. Once a keypress is detected, the mouse is enabled.

Disable the mouse

First, we install xinput with

sudo apt-get install xinput

Then try the command xinput list. This gives details of the mouse and keyboard, with an ID number for each. Say, for instance that the mouse ID is 8. Then the mouse can be disabled by the command:

xinput set=prop 8 "Device Enabled" "0"

Enable the mouse

So far so good. Now, how to get the mouse working again when a key is pressed? The mouse is enabled with the command

xinput set=prop 8 "Device Enabled" "1"

so we have to detect any keypress and run that command, at least once (ideally), or after every keypress forever (not so nice).

To detect keypress, I have experimented with something called actkbd, a daemon process that depends on the kernel module evdev (sudo modprobe evdev). It hasn't proved to work and maybe thats something to do with the fact the documentation says it was written for kernel 2.6. We are currently using linux kernel 4.4.

I've also tried esekeyd. It is is supposed to do something similar -intercept key presses and run a process when it sees a key or a key combination. I've had no luck with it either, so that's where i'm stuck.

Maybe someone else will come along and make it work, or devise a different scheme completely.

Making the ID match the mouse

Turning back to disabling the mouse, there's no guarantee that the mouse will always appear with ID 8 as in my example above. So the mouse disable process, run once during the 'new-session' script should discover the mouse ID, store the ID in the new clean user home space, and then disable the mouse. Like this:

ID=$( xinput list | grep [Mm]ouse | sed 's/^.*id=\([0-9][0-9]*\).*$/\1/'

echo $ID >/home/viny/.cache/mouse-id

xinput set-prop $ID "Device Enabled" "0"

When it's time to re-enable the mouse, the ID can be found in the cache, and used in the xinput set-prop command.