> 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
[email protected]
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines

Reply via email to