The requirement is to wake the computer from a sleep or power-saving mode when any keyboard key is pressed, but not to wake uo 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 it 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.
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"
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.
There's something else. Its called esekeyd, and 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.
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.