device activity checking for powersaver on a linux laptop
Fabian Lienert
lienert at mitlinks.ch
Sat Feb 1 17:22:13 EST 2003
Dear pythonists,
I am new to python and want to write a program, that saves battery power on
a linux laptop. For example it should power off the display, when there is no
keyboard or mouse activity for a minute.
My first problem is: I cannot found a /dev device for the keyboard. And raw_input doesn't make sense,
because it is like a prompt, its impossible to check for keyboard activity.
So i focused first on the mouse. Here I know the linux device is /dev/psaux. I can "cat /dev/psaux" on
a shell and see that there is some input if i use the mouse. So i wrote a quick test script like this:
--
import string,re,time,sys
class Idle:
def __init__(self):
import sys,time
mouse_dev = open('/dev/psaux','r')
while mouse_dev:
if mouse_dev == '':
time.sleep(60)
open('/dev/psaux','r')
print "Idle"
continue
else:
print mouse_dev
continue
--
It does not work, as you see, because mouse_dev is an existing object, it is not == ''
Also with mouse_dev.read(): doesn't work.
How can I check if the mouse_dev is "empty" in the meaning that there is no
activity?
And how can I check for keyboard activity?
Thanks in advance for help!
Fabian
--
Fabian Lienert | mitLinks AG | Limmatstrasse 291 | 8005 Zürich
lienert at mitlinks.ch | ++41 1 444 10 44 | http://www.mitlinks.ch
lynx -dump www.mitlinks.ch/keys/lienert.asc | gpg --import
More information about the Python-list
mailing list