Solved

Finding whether the keyboard is used

Posted on 1998-09-10
11
180 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!
0
Comment
Question by:ShadowHawk071998
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +3
11 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1172462
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?
0
 
LVL 7

Expert Comment

by:psdavis
ID: 1172463
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

0
 
LVL 22

Expert Comment

by:nietod
ID: 1172464
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:psdavis
ID: 1172465
Hmm... Good point.  I defer.  Thanks nietod.

Phillip
0
 
LVL 11

Expert Comment

by:alexo
ID: 1172466
SetWindowHookEx() for Win32 platforms.

0
 
LVL 2

Expert Comment

by:duneram
ID: 1172467
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.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1172468
>> 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...
0
 
LVL 4

Expert Comment

by:pagladasu
ID: 1172469
I agree with alexo. The points are really secondary - its the exchange of information and knowledge that matters.
0
 

Author Comment

by:ShadowHawk071998
ID: 1172470
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.
0
 
LVL 11

Accepted Solution

by:
alexo earned 100 total points
ID: 1172471
>> Can someone give a small example on how to use hooks? I haven't done it before.
You've come to the right person!

In order to set up a hook, call SetWindowsHookEx().  If you want the hook to be system-wide, put the hook code in a DLL and the hook handle in shared memory.

Confused?  See http://www.experts-exchange.com/Q.10063288 (5 points) or ask here.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1172472
And the autograder hits again!
Thank you so much for your consideration.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question