By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,795 Members | 1,660 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,795 IT Pros & Developers. It's quick & easy.

Getting time of last mouse click and keystroke?

P: n/a
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
Mar 7 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

Mar 7 '06 #2

P: n/a
Andy wrote:
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.
Mar 8 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.