Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Windows idle time

Windows idle time

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
21 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Florin Ochiana

    Hi, I want to do something in my app when the user doesn't do anything for a period of time (doesn't move the mouse and doesn't touch any key on the keyboard). MSN Messenger, for example, makes you idle when you are inactive. I want to lock some sections of my app. How can I test this from my app? How can I get the windows idle time? Thanks ----- We are what we repeatedly do. Excellence, then, is not an act, but a habit.

    R Offline
    R Offline
    Rage
    wrote on last edited by
    #2

    You could use : virtual BOOL CWinApp::OnIdle( LONG lCount ); Or maybe, use a timer and handle WM_MOUSE_MOVE and WM_KEY_DOWN but this is resource consuming ( I mean polling all the time to see if something changes). ~RaGE();

    F 1 Reply Last reply
    0
    • R Rage

      You could use : virtual BOOL CWinApp::OnIdle( LONG lCount ); Or maybe, use a timer and handle WM_MOUSE_MOVE and WM_KEY_DOWN but this is resource consuming ( I mean polling all the time to see if something changes). ~RaGE();

      F Offline
      F Offline
      Florin Ochiana
      wrote on last edited by
      #3

      I don't want the idle time in my app. In windows in general. I thought OnIdle is called when the application is idle. ----- We are what we repeatedly do. Excellence, then, is not an act, but a habit.

      R 1 Reply Last reply
      0
      • F Florin Ochiana

        I don't want the idle time in my app. In windows in general. I thought OnIdle is called when the application is idle. ----- We are what we repeatedly do. Excellence, then, is not an act, but a habit.

        R Offline
        R Offline
        Rage
        wrote on last edited by
        #4

        Then you'll have to set a hook on the mouse and the keyboard inputs, that's the only way to know that nothing happened in "windows in general". Search for hook on Code Project (especially the article by J. Newcomer). ~RaGE();

        F 1 Reply Last reply
        0
        • R Rage

          Then you'll have to set a hook on the mouse and the keyboard inputs, that's the only way to know that nothing happened in "windows in general". Search for hook on Code Project (especially the article by J. Newcomer). ~RaGE();

          F Offline
          F Offline
          Florin Ochiana
          wrote on last edited by
          #5

          Thanks for your time. Regards, ----- We are what we repeatedly do. Excellence, then, is not an act, but a habit.

          1 Reply Last reply
          0
          • F Florin Ochiana

            Hi, I want to do something in my app when the user doesn't do anything for a period of time (doesn't move the mouse and doesn't touch any key on the keyboard). MSN Messenger, for example, makes you idle when you are inactive. I want to lock some sections of my app. How can I test this from my app? How can I get the windows idle time? Thanks ----- We are what we repeatedly do. Excellence, then, is not an act, but a habit.

            A Offline
            A Offline
            avenger_sb25
            wrote on last edited by
            #6

            I think this might be of some help: GetLastInputInfo The GetLastInputInfo function retrieves the time of the last input event. BOOL GetLastInputInfo( PLASTINPUTINFO plii // last input event ); Parameters plii [out] Pointer to a LASTINPUTINFO structure that receives the time of the last input event. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. Remarks This is useful for input idle detection


            Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs

            R 1 Reply Last reply
            0
            • A avenger_sb25

              I think this might be of some help: GetLastInputInfo The GetLastInputInfo function retrieves the time of the last input event. BOOL GetLastInputInfo( PLASTINPUTINFO plii // last input event ); Parameters plii [out] Pointer to a LASTINPUTINFO structure that receives the time of the last input event. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. Remarks This is useful for input idle detection


              Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs

              R Offline
              R Offline
              Rage
              wrote on last edited by
              #7

              I'm just curious, where does this comes from ? the online MSDN ? I do not have it in my 2000 version. :doh: ~RaGE();

              A D 2 Replies Last reply
              0
              • R Rage

                I'm just curious, where does this comes from ? the online MSDN ? I do not have it in my 2000 version. :doh: ~RaGE();

                A Offline
                A Offline
                Antony M Kancidrowski
                wrote on last edited by
                #8

                It is in the later MSDN libraries and on-line! :) I know it isn't in the standard MSDN libs that come with VC6. Ant.

                1 Reply Last reply
                0
                • R Rage

                  I'm just curious, where does this comes from ? the online MSDN ? I do not have it in my 2000 version. :doh: ~RaGE();

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #9

                  Here is a link to the entire article. However, if you are using Windows 9x or NT, you'll need to employ a system-wide hook. See this article for details.


                  "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                  A 1 Reply Last reply
                  0
                  • D David Crow

                    Here is a link to the entire article. However, if you are using Windows 9x or NT, you'll need to employ a system-wide hook. See this article for details.


                    "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                    A Offline
                    A Offline
                    Anonymous
                    wrote on last edited by
                    #10

                    GetLastInputInfo not working properly in Windows 2000 Error: Undefined Identifier for GetLastInputInfo please explain Jack

                    A D 2 Replies Last reply
                    0
                    • A Anonymous

                      GetLastInputInfo not working properly in Windows 2000 Error: Undefined Identifier for GetLastInputInfo please explain Jack

                      A Offline
                      A Offline
                      avenger_sb25
                      wrote on last edited by
                      #11

                      This is what MSDN says: Requirements Windows NT/2000: Requires Windows NT 3.1 or later. Windows 95/98: Requires Windows 95 or later. Header: Declared in Winuser.h; include Windows.h. Library: Use user32.lib. And what do you mean by not working properly? Can u give details on the improper working? ...Avenger


                      Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs

                      D 1 Reply Last reply
                      0
                      • A Anonymous

                        GetLastInputInfo not working properly in Windows 2000 Error: Undefined Identifier for GetLastInputInfo please explain Jack

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #12

                        Please provide a code snippet of how you are using the function.


                        "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                        B 1 Reply Last reply
                        0
                        • A avenger_sb25

                          This is what MSDN says: Requirements Windows NT/2000: Requires Windows NT 3.1 or later. Windows 95/98: Requires Windows 95 or later. Header: Declared in Winuser.h; include Windows.h. Library: Use user32.lib. And what do you mean by not working properly? Can u give details on the improper working? ...Avenger


                          Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs

                          D Offline
                          D Offline
                          David Crow
                          wrote on last edited by
                          #13

                          avenger_sb25 wrote: Windows 95/98: Requires Windows 95 or later. The function is not available on Windows 9x platforms.


                          "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                          1 Reply Last reply
                          0
                          • D David Crow

                            Please provide a code snippet of how you are using the function.


                            "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                            B Offline
                            B Offline
                            Bharat Gidde
                            wrote on last edited by
                            #14

                            I am using Windows 2000 here is the snippet #include "stdafx.h" int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { LASTINPUTINFO plii; memset(&plii,0,sizeof(plii)); plii.cbSize = size(plii); if(GetLastInputInfo(&plii )) { //code here } return 0; } Even if I declare the LASTINPUTINFO structure in the header file its not working Sandy

                            D 1 Reply Last reply
                            0
                            • B Bharat Gidde

                              I am using Windows 2000 here is the snippet #include "stdafx.h" int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { LASTINPUTINFO plii; memset(&plii,0,sizeof(plii)); plii.cbSize = size(plii); if(GetLastInputInfo(&plii )) { //code here } return 0; } Even if I declare the LASTINPUTINFO structure in the header file its not working Sandy

                              D Offline
                              D Offline
                              David Crow
                              wrote on last edited by
                              #15

                              Well, since what you have is not a true Windows application (e.g., you need a window and a message pump), I'm not sure how GetLastInputInfo() is supposed to behave. I may be incorrect, but it wouldn't hurt to at least provide the minimum.


                              "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                              A 1 Reply Last reply
                              0
                              • D David Crow

                                Well, since what you have is not a true Windows application (e.g., you need a window and a message pump), I'm not sure how GetLastInputInfo() is supposed to behave. I may be incorrect, but it wouldn't hurt to at least provide the minimum.


                                "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                                A Offline
                                A Offline
                                Anonymous
                                wrote on last edited by
                                #16

                                Even if I provide a window and check the messages it gives a error saying "Undefined Identifier for "GetLastInputInfo() Jack

                                D 1 Reply Last reply
                                0
                                • A Anonymous

                                  Even if I provide a window and check the messages it gives a error saying "Undefined Identifier for "GetLastInputInfo() Jack

                                  D Offline
                                  D Offline
                                  David Crow
                                  wrote on last edited by
                                  #17

                                  Is this a compiler, linker, or run-time error?


                                  "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                                  A 1 Reply Last reply
                                  0
                                  • D David Crow

                                    Is this a compiler, linker, or run-time error?


                                    "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                                    A Offline
                                    A Offline
                                    Anonymous
                                    wrote on last edited by
                                    #18

                                    compiler error! Jack

                                    D 1 Reply Last reply
                                    0
                                    • A Anonymous

                                      compiler error! Jack

                                      D Offline
                                      D Offline
                                      David Crow
                                      wrote on last edited by
                                      #19

                                      What other files are being #included in stdafx.h?


                                      "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                                      A 1 Reply Last reply
                                      0
                                      • D David Crow

                                        What other files are being #included in stdafx.h?


                                        "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                                        A Offline
                                        A Offline
                                        Anonymous
                                        wrote on last edited by
                                        #20

                                        Only the windows.h and the winuser.h Jack

                                        D 1 Reply Last reply
                                        0
                                        • A Anonymous

                                          Only the windows.h and the winuser.h Jack

                                          D Offline
                                          D Offline
                                          David Crow
                                          wrote on last edited by
                                          #21

                                          Have you defined _WIN32_WINNT? If not, look at line #5040 of winuser.h.


                                          "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups