monitoring - Monitor user activity in vb.net -
i make program monitors user activity. not need know user doing, need know is doing something. moving mouse, or typing. program used show company @ desk , gone workstation. if there no activity 2 minutes, means user away computer.
i thinking of using keyboard hook , mouse position monitor changes every lets 5 seconds. on every change reset counter.
is there better way? (for example reading screensaver countdown or that)
you can p/invoke winapi's getlastinputinfo()
function able millisecond count @ point last input received since computer started.
subtracting environment.tickcount
above give how many milliseconds have lapsed since last input received:
<dllimport("user32.dll")> _ public shared function getlastinputinfo(byref plii lastinputinfo) boolean end function <structlayout(layoutkind.sequential)> _ public structure lastinputinfo <marshalas(unmanagedtype.u4)> _ public cbsize integer <marshalas(unmanagedtype.u4)> _ public dwtime integer end structure private sub timer1_tick(sender system.object, e system.eventargs) handles timer1.tick dim lastinput new lastinputinfo {.cbsize = marshal.sizeof(gettype(lastinputinfo))} 'the "cbsize" field must set every time call function. if getlastinputinfo(lastinput) = true andalso _ (environment.tickcount - lastinput.dwtime) >= 120000 '120000 ms = 120 s = 2 min. timer1.stop() 'computer has been idle 2 minutes. stuff here. end if end sub
this check both mouse , keyboard input.
the timer's interval
property set 5000
make check every 5 seconds, , enabled
property set true
.
keep in mind must restart timer after 2 minutes of idle time have lapsed if want check again.
Comments
Post a Comment