views:

1513

answers:

3

Hi all, I need some way to detect mouse/keyboard activity on Linux. something similar to what any IM program would do, if no actiivty is dected for say 5minutes, it will set your IM status to "I'm not here right now" Any help towards this is appreciated. Thanks

A: 

try executing who -u -H at the command line. It'll tell you who's logged in and how long they've been idle. At least users logged in to a terminal; I don't think it works at all in X. Anyhow, with this information you can tell who's idle or not and take actions appropriately.

If you're in X you could create a script to run as a screen saver or something like that.

Keith Twombley
A: 

For the idle section of your code you'll want some sort of timer that just counts down from 5 minutes (or whatever time frame you like).

Whenever the user hits a key or moves the mouse, you reset the timer.

The specifics of how to gather the mouse click/move or key press events will depend on what language you are using to write you program.

Jeffrey Martinez
+1  A: 

Don't poll when there's better methods available.

You don't specify the environment, but since you mention the mouse, I'm going to assume modern X11.

xidle uses the MIT-SCREEN-SAVER extension to determine whether the user is idle or not -- you can use xidle directly, or read its source code to learn how to use the XScreenSaver(3) yourself.

Edit

man 3 XScreenSaver -- just use the idle-reporting/notification portions of it, since there is no more XIDLE extension since X11R6.

ephemient