mouse hook and a keyboard hook to monitor global user interactions
- Hi all
Is it possible to monitor the global Mouse and Keyboard interactions?
Before posting this question i got the following reference but the page links which are give in below thread are not present now.
So asking it again. :)
Is possible to know when the PocketPC is not in use for a while?
Thanks.
Regards,
Amit Rote
Answers
- On what device/version? I don't have a lot of experience with doing this on
Pocket PCs, but in Windows CE itself, look at the following registry value:
HKLM/System/GWE/ActivityEvent
This is the name of the event that GWES, the windowing system, fires
whenever it thinks that it has user activity. If you get that name and
create an event with that name, you should be hooked to the GWES event
system and that event should be set each time there's user activity.
Something like this (native code, for now):
event = CreateEvent(..., eventnamefromregistry);
while ( 1 )
{
switch( WaitForSingleObject( event, timeout ) )
{
case WAIT_OBJECT_0:
// User activity occurred before a time-out. Presumably, you'll
just wait again, in this
// case.
break;
default: // WAIT_TIMEOUT (or error)
// No user activity for the timeout period. Do whatever you
want to do in that, idle,
// case.
break;
}
}
Paul T.
"Amit Rote" <=?utf-8?B?QW1pdCBSb3Rl?=> wrote in message
news:a3678d20-2f22-4a97-b032-452ea16d7286...
> Hi all,
>
> Now let me explain the exact requirement which is as follows.
>
> 1) Initially when application will launch. it will run in background.
> 2) While running in the background, it will monitor the user interactions.
> Now here monitoring means ultimately background application is looking for
> the Idle time threshold (say 5 mins). And when(background application)?
> realize that the system is Idle for 5 mins then it will launch some UI
> screen.
>
> So i am looking for How I can detect the Idleness of the system? And also
> if user interacts again before the threshold time(here it is 5 mins) then
> i will look for the next session of System Idleness.
>
> Hope this explanations clears what exactly i am looking for.
> Please let me know if you have any doubts regarding the same.
>
> Guys, its urgent please help me out. :)
>
> Thanks.
> Regards,
> Amit Rote- Marked As Answer byChunsheng TangMSFT, ModeratorWednesday, July 01, 2009 12:48 AM
Keyboard hooks work on Windows Mobile but it's undocumented. Here is a sample:
Keyboard hook in the CF v2
http://blog.opennetcf.com/ayakhnin/PermaLink,guid,84b95802-76d7-499c-b266-e2251ab15706.aspx
Mouse hooks simply don't work on Windows Mobile.
(EDIT: Keyboard hooks work but Mouse hooks don't)
Please mark the post that helps you, and unmark that does not. This benefits our community members.- Edited byChunsheng TangMSFT, ModeratorTuesday, June 30, 2009 7:17 AM
- Marked As Answer byChunsheng TangMSFT, ModeratorWednesday, July 01, 2009 12:48 AM
- Unmarked As Answer byAmit Rote Thursday, July 02, 2009 5:34 AM
- Marked As Answer byAmit Rote Thursday, July 02, 2009 5:35 AM
- If what I described doesn't fit your need, you have not properly defined what you are after. Using the activity timer WILL allow you to do precisely what you said you wanted to do. No, you can't hook mouse messages. If you could, the first answer would have been just "Yes, use the hook constant XYZ". If you have additional requirements that you've been keeping to yourself, tell us what those are and we might be able to suggest something, but I can't see any reason why knowing that a touch has occurred or that the mouse has moved would help you at all to accomplish what you say you want to do.
Paul T.- Marked As Answer byAmit Rote Friday, July 17, 2009 5:21 AM
All Replies
- Hi all,
Now let me explain the exact requirement which is as follows.
1) Initially when application will launch. it will run in background.
2) While running in the background, it will monitor the user interactions. Now here monitoring means ultimately background application is looking for the Idle time threshold (say 5 mins). And when(background application) realize that the system is Idle for 5 mins then it will launch some UI screen.
So i am looking for How I can detect the Idleness of the system? And also if user interacts again before the threshold time(here it is 5 mins) then i will look for the next session of System Idleness.
Hope this explanations clears what exactly i am looking for.
Please let me know if you have any doubts regarding the same.
Guys, its urgent please help me out. :)
Thanks.
Regards,
Amit Rote - Hello mohsin,
Thanks for the reply.
The link you shared is related to the PowerManagement and not exactly for what i am looking.
Regards,
amit rote - On what device/version? I don't have a lot of experience with doing this on
Pocket PCs, but in Windows CE itself, look at the following registry value:
HKLM/System/GWE/ActivityEvent
This is the name of the event that GWES, the windowing system, fires
whenever it thinks that it has user activity. If you get that name and
create an event with that name, you should be hooked to the GWES event
system and that event should be set each time there's user activity.
Something like this (native code, for now):
event = CreateEvent(..., eventnamefromregistry);
while ( 1 )
{
switch( WaitForSingleObject( event, timeout ) )
{
case WAIT_OBJECT_0:
// User activity occurred before a time-out. Presumably, you'll
just wait again, in this
// case.
break;
default: // WAIT_TIMEOUT (or error)
// No user activity for the timeout period. Do whatever you
want to do in that, idle,
// case.
break;
}
}
Paul T.
"Amit Rote" <=?utf-8?B?QW1pdCBSb3Rl?=> wrote in message
news:a3678d20-2f22-4a97-b032-452ea16d7286...
> Hi all,
>
> Now let me explain the exact requirement which is as follows.
>
> 1) Initially when application will launch. it will run in background.
> 2) While running in the background, it will monitor the user interactions.
> Now here monitoring means ultimately background application is looking for
> the Idle time threshold (say 5 mins). And when(background application)?
> realize that the system is Idle for 5 mins then it will launch some UI
> screen.
>
> So i am looking for How I can detect the Idleness of the system? And also
> if user interacts again before the threshold time(here it is 5 mins) then
> i will look for the next session of System Idleness.
>
> Hope this explanations clears what exactly i am looking for.
> Please let me know if you have any doubts regarding the same.
>
> Guys, its urgent please help me out. :)
>
> Thanks.
> Regards,
> Amit Rote- Marked As Answer byChunsheng TangMSFT, ModeratorWednesday, July 01, 2009 12:48 AM
Hi Paul T.
Thanks for the reply.
However, I need to target both the platforms PocketPC and Smartphones.
Regards,
Amit RoteKeyboard hooks work on Windows Mobile but it's undocumented. Here is a sample:
Keyboard hook in the CF v2
http://blog.opennetcf.com/ayakhnin/PermaLink,guid,84b95802-76d7-499c-b266-e2251ab15706.aspx
Mouse hooks simply don't work on Windows Mobile.
(EDIT: Keyboard hooks work but Mouse hooks don't)
Please mark the post that helps you, and unmark that does not. This benefits our community members.- Edited byChunsheng TangMSFT, ModeratorTuesday, June 30, 2009 7:17 AM
- Marked As Answer byChunsheng TangMSFT, ModeratorWednesday, July 01, 2009 12:48 AM
- Unmarked As Answer byAmit Rote Thursday, July 02, 2009 5:34 AM
- Marked As Answer byAmit Rote Thursday, July 02, 2009 5:35 AM
I didn't say it *wouldn't* work in WM, just that I haven't done it. Have you tried it?
Paul T.Keyboard hooks work on Windows Mobile but it's undocumented. Here is a sample:
Keyboard hook in the CF v2
http://blog.opennetcf.com/ayakhnin/PermaLink,guid,84b95802-76d7-499c-b266-e2251ab15706.aspx
Mouse hooks simply don't work on Windows Mobile.
(EDIT: Keyboard hooks work but Mouse hooks don't)
Please mark the post that helps you, and unmark that does not. This benefits our community members.
Hi Chunsheng,
Thanks for the reply.
However, in case of mouse interactions monitor i mean here to monitor the thouch screen interactions.
So is it not possible to monitor those touch screen interactions?
Regards,
Amit Rote- Hi All,
Now as per Paul T i can make use of ActivityTimer. However, depending on the registry values will not be that much reliable as per my requirement. Because user can install any of the application which may interacting with the ActivityTimer and related registry values.
And as Chunsheng suggested, I can hook the Keyboard.
However, still in case of monitoring the mouse interactions(touch screen interactions) i didnt get any answer.
So is it not possible to monitor those touch screen interactions also?
Regards,
Amit Rote - If what I described doesn't fit your need, you have not properly defined what you are after. Using the activity timer WILL allow you to do precisely what you said you wanted to do. No, you can't hook mouse messages. If you could, the first answer would have been just "Yes, use the hook constant XYZ". If you have additional requirements that you've been keeping to yourself, tell us what those are and we might be able to suggest something, but I can't see any reason why knowing that a touch has occurred or that the mouse has moved would help you at all to accomplish what you say you want to do.
Paul T.- Marked As Answer byAmit Rote Friday, July 17, 2009 5:21 AM
- Hi Paul T,
Sorry for long time to reply. :)
I checked with the HKLM/System/GWE/ActivityEvent and its working exactly wt the requirement is.
Thanks for your answer.
Regards,
Amit R. hey,
I'm looking for the exact thing.
did you managed to work it out?The following thread show two other ways to detect user idle state which are better than hooks:
http://social.msdn.microsoft.com/Forums/en-US/windowsmobiledev/thread/11b65614-678a-45ea-b1d4-f44e9a2c7915
Please mark the post that helps you, and unmark that does not. This benefits our community members.

