We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Finding whether the keyboard is used

ShadowHawk071998
on
Medium Priority
199 Views
Last Modified: 2010-04-02
Hello.
I need to find whether a keyboard was used. I guess that what I should actually do is use a hook, to catch keyboard
messages. How do I do it?
What I'm actually trying to achieve is to decide whether the computer was used in the past 5 minutes. I thought I'd just look at the keyboard, and if it was pressed, than the computer was used (I also sense the mouse, but I know how to do this). Please help!
Comment
Watch Question

Commented:
If this is windows, you can use a hook to intercept all the keyboard messages and record the time of each message, then note when the last message is more than 5 minutes old.  Take a look at SetWindowHook().

If this is not for windows, what OS is this for?

Commented:
I'd simply capture the WM_CHAR and/or the WM_KEYDOWN.  If you're using MFC, then override for the OnChar and/or the OnKeyDown methods.  Both are easy to use and will be very similar to the WM_MOUSEMOVE or the MouseMove method.

Phillip

Commented:
Except an application only gets the char/key messages if it has the focus.  Thus, the user could be using the computer, but with this application in the background, and the application would think the computer is idle.

Commented:
Hmm... Good point.  I defer.  Thanks nietod.

Phillip

Commented:
SetWindowHookEx() for Win32 platforms.

Commented:
I have a full proof solution that works on all windows platforms  but its worth way more than 100 points.  It took about 3 months to develop and lots of hard work using softice to figure out how ms windows works.

An alternative is the keyboard hook method mentioned before.  it would do a fair job.

Commented:
>> I have a full proof solution that works on all windows platforms  but its worth way more than 100 points.

Duneram, most of us are here because we want to help and share knowledge.  If your solution is a trade secret you shouldn't even mention it here.  Otherwise, what difference does the number of "points" make?  They won't make your accountant any happier...
I agree with alexo. The points are really secondary - its the exchange of information and knowledge that matters.

Author

Commented:
Thanks guyz.
I AM using windows, (The compiler is VC++) and I'm NOT using MFC. Can someone give a small example on how to use hooks? I haven't done it before.
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:
And the autograder hits again!
Thank you so much for your consideration.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.