Getting time of last mouse click and keystroke?

B

beaker

Hello,

I'm writing a program (which will be running in the background 99% of
the time) and I want to be able to work out how long it has been since
the user last used the mouse and/or keyboard. I plan on using a Timer
to do the checking periodically, but I'm not sure how to get the time of
the last mouse click or keystroke.

Any suggestions? I've seen examples on keyboard loggers but they seem
to focus on capturing all keystrokes, and I'm only interested in their time.

Thanks in advance,

Gary
 
A

Andy

Sounds like you'd need a static DateTime member somewhere that the
timer can see. For every keystroke or mouse movement, set the member
to DateTime.Now.

When your timer fires, you can take DateTime.Now and the static member
and do the math.

HTH
Andy
 
B

beaker

Andy said:
Sounds like you'd need a static DateTime member somewhere that the
timer can see. For every keystroke or mouse movement, set the member
to DateTime.Now.

When your timer fires, you can take DateTime.Now and the static member
and do the math.

HTH
Andy


Thanks for that. In the end I decided to go with GetLastInputInfo() in
user32.dll and forsake Windows 9x compatibility.

I did try what you suggested with some hooks to intecept all mouse and
key clicks, but my boss was worried that 'spyware detectors' might
interpret this as a fully fledgedkey logger - don't know how likely that
is though.

Cheers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top