Windows Mobile Developer Center > Smart Device Development Forums > .NET Compact Framework > mouse hook and a keyboard hook to monitor global user interactions
Ask a questionAsk a question
 

Answermouse hook and a keyboard hook to monitor global user interactions

Answers

  • Thursday, June 25, 2009 4:56 PMPaul G. TobeyMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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


  • Monday, June 29, 2009 10:10 AMChunsheng TangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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.
  • Thursday, July 02, 2009 3:47 PMPaul G. TobeyMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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

  • Thursday, June 25, 2009 8:03 AMAmit Rote Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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
  • Thursday, June 25, 2009 8:13 AMMohsin S Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Amit ,

    Are you talking about this ?


    Thanks Mohsin S.
  • Thursday, June 25, 2009 8:53 AMAmit Rote Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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
  • Thursday, June 25, 2009 4:56 PMPaul G. TobeyMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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


  • Friday, June 26, 2009 6:27 AMAmit Rote Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Paul T.

    Thanks for the reply.

    However, I need to target both the platforms PocketPC and Smartphones.

    Regards,
    Amit Rote

  • Monday, June 29, 2009 10:10 AMChunsheng TangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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.
  • Monday, June 29, 2009 4:51 PMPaul G. TobeyMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I didn't say it *wouldn't* work in WM, just that I haven't done it.  Have you tried it?

    Paul T.

  • Thursday, July 02, 2009 5:38 AMAmit Rote Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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
  • Thursday, July 02, 2009 11:52 AMAmit Rote Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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
  • Thursday, July 02, 2009 3:47 PMPaul G. TobeyMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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
    •  
  • Friday, July 17, 2009 5:21 AMAmit Rote Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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.
  • Tuesday, September 01, 2009 11:20 AMelad2109 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    hey,

    I'm looking for the exact thing.

    did you managed to work it out?

  • Wednesday, September 02, 2009 3:52 AMChunsheng TangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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.