Did you know LQ has a Linux Hardware Compatibility List?
Go Back > Blogs > linux-related notes
User Name


Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Rate this Entry

Bash script/utility to wait for keyboard and mouse inactivity

Posted 10-18-2013 at 07:42 PM by the dsc
Updated 10-22-2013 at 08:52 PM by the dsc

Sometimes you may want to have some script periodically popping up some interface or something, but it may be somewhat abrupt, interrupt something you're doing with the mouse, or keyboard. So I came up with this tiny utility that will wait for the time given as a parameter, then exit.

if [ -z $time ] ; then time="1.2s" ; fi

while true ; do

mouse1=$( xdotool getmouselocation --shell | head -n 1 | sed 's|X=||')
kb1=$( grep i8042 /proc/interrupts | awk '{ print $2}' )

sleep $time

mouse2=$( xdotool getmouselocation --shell | head -n 1 | sed 's|X=||')
kb2=$( grep i8042 /proc/interrupts | awk '{ print $2}' )

if [ $mouse1 -eq $mouse2 ] && [ $kb1 -eq $kb2 ] ; then
echo ...

if [ $a -gt 4 ] ; then

# echo xscreensaver action

exit 0



echo user activity...


I don't even understand how the detection of keyboard activity works, I got it from somewhere, and works in my hardware.

Usage example: " && mypopsubroutine", if you have the script in your "path", or it converted in a sobroutine into the script itself.
Posted in Uncategorized
Views 654 Comments 0
« Prev     Main     Next »
Total Comments 0




All times are GMT -5. The time now is 04:25 AM.

Main Menu

Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration