Re: How to mesure the inactivity time

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> I am developping a tool with java and I want to know the inactivity time of
> the user, i.e, the duration of the time that the keybord and mouse were not
> used.

You can check out my typing/mousing activity monitor written in
Tcl/Tk for helping people with RSI to take programmed rest
breaks: http://www.omnisterra.com/walker/linux/tm-1.2.tar

    Here's the core code:

     proc get_idle {t m d} {
	upvar $m midle		;# mouse idle time
	upvar $t tidle		;# typing idle time
	upvar $d delta_time

	global now
	global x
	global y
	global xold
	global yold

	set then $now
	set now [clock seconds]

	set delta_time [expr $now-$then]

	set f [open {| cat /proc/interrupts}]
	while {[gets $f line] >= 0} {
	   if [regexp " 12:" $line] {
	       set xold $x
	       set x [lindex $line 1]
	   } elseif [regexp " 1:" $line] {
	       set yold $y
	       set y [lindex $line 1]
	   }
	}
	close $f

	if {$yold == $y} {
	   set tidle [expr $tidle + $delta_time]
	} else {
	   set tidle 0
	}

	if {$xold == $x} {
	   set midle [expr $midle + $delta_time]
	} else {
	   set midle 0
	}
    }

It basically looks for the mouse interrupt count (12:) and the keyboard
interrupt (1:).  If you have keyboard or mouse on USB you'll need
to look at (5:) instead.  "cat /proc/interrupts" returns a list
of interrrupt numbers and a running count.  If the count hasn't
changed since the last poll, then I consider this an idle
condition and increment the idle counters by the difference in
time between the last polling event and "now".

--
Rick Walker


-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux