LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Blogs > linux-related notes
User Name
Password

Notices

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 06:42 PM by the dsc
Updated 10-22-2013 at 07: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.



Code:
#!/bin/bash
a=0
time=$1
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
a=$((a+1))
echo ...

if [ $a -gt 4 ] ; then

# echo xscreensaver action

exit 0

fi

else

a=0
echo user activity...

fi

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

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

Comments

 

  



All times are GMT -5. The time now is 06:55 AM.

Main Menu

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