Execute function on user inactivity [closed] The 2019 Stack Overflow Developer Survey Results Are InHow to check whether the device's display is turned on/off with Python?Calling a function of a module by using its name (a string)How to flush output of print function?How to return multiple values from a function?Using global variables in a functionmkdir -p functionality in PythonHow to make a chain of function decorators?How do I get time of a Python program's execution?How to detect user inactivity in AndroidJavascript disabled after a period of user inactivityHow to detect inactivity in VB.NET

Landlord wants to switch my lease to a "Land contract" to "get back at the city"

What to do when moving next to a bird sanctuary with a loosely-domesticated cat?

What does ひと匙 mean in this manga and has it been used colloquially?

During Temple times, who can butcher a kosher animal?

If a Druid sees an animal’s corpse, can they wild shape into that animal?

Can one be advised by a professor who is very far away?

How to notate time signature switching consistently every measure

Is there any way to tell whether the shot is going to hit you or not?

Did Scotland spend $250,000 for the slogan "Welcome to Scotland"?

Can someone be penalized for an "unlawful" act if no penalty is specified?

Can you compress metal and what would be the consequences?

FPGA - DIY Programming

Can a rogue use sneak attack with weapons that have the thrown property even if they are not thrown?

Are there any other methods to apply to solving simultaneous equations?

Why was M87 targetted for the Event Horizon Telescope instead of Sagittarius A*?

How to type this arrow in math mode?

Where to refill my bottle in India?

Identify boardgame from Big movie

One word riddle: Vowel in the middle

What do hard-Brexiteers want with respect to the Irish border?

What does Linus Torvalds mean when he says that Git "never ever" tracks a file?

Resizing object distorts it (Illustrator CC 2018)

Is this app Icon Browser Safe/Legit?

For what reasons would an animal species NOT cross a *horizontal* land bridge?



Execute function on user inactivity [closed]



The 2019 Stack Overflow Developer Survey Results Are InHow to check whether the device's display is turned on/off with Python?Calling a function of a module by using its name (a string)How to flush output of print function?How to return multiple values from a function?Using global variables in a functionmkdir -p functionality in PythonHow to make a chain of function decorators?How do I get time of a Python program's execution?How to detect user inactivity in AndroidJavascript disabled after a period of user inactivityHow to detect inactivity in VB.NET



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















At work we have to do our own time management and get controlled from time to time. Because I always forget, when I take my breaks and how long, I decided to write a python script which runs on startup and writes the current time after I haven't moved my mouse or typed on my keyboard for 5 minutes.



import datetime


def writetime():
t = datetime.datetime.now()

with open("C:\Users\[USER]\Desktop\time.txt", 'a') as f:
f.write('%s n' % t)


I just don't know, how to execute my function writetime after a certain amount of time elapsed since the last input.










share|improve this question















closed as too broad by Marcin Orlowski, stovfl, thewaywewere, Deadpool, mao Mar 8 at 19:29


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
























    0















    At work we have to do our own time management and get controlled from time to time. Because I always forget, when I take my breaks and how long, I decided to write a python script which runs on startup and writes the current time after I haven't moved my mouse or typed on my keyboard for 5 minutes.



    import datetime


    def writetime():
    t = datetime.datetime.now()

    with open("C:\Users\[USER]\Desktop\time.txt", 'a') as f:
    f.write('%s n' % t)


    I just don't know, how to execute my function writetime after a certain amount of time elapsed since the last input.










    share|improve this question















    closed as too broad by Marcin Orlowski, stovfl, thewaywewere, Deadpool, mao Mar 8 at 19:29


    Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.




















      0












      0








      0








      At work we have to do our own time management and get controlled from time to time. Because I always forget, when I take my breaks and how long, I decided to write a python script which runs on startup and writes the current time after I haven't moved my mouse or typed on my keyboard for 5 minutes.



      import datetime


      def writetime():
      t = datetime.datetime.now()

      with open("C:\Users\[USER]\Desktop\time.txt", 'a') as f:
      f.write('%s n' % t)


      I just don't know, how to execute my function writetime after a certain amount of time elapsed since the last input.










      share|improve this question
















      At work we have to do our own time management and get controlled from time to time. Because I always forget, when I take my breaks and how long, I decided to write a python script which runs on startup and writes the current time after I haven't moved my mouse or typed on my keyboard for 5 minutes.



      import datetime


      def writetime():
      t = datetime.datetime.now()

      with open("C:\Users\[USER]\Desktop\time.txt", 'a') as f:
      f.write('%s n' % t)


      I just don't know, how to execute my function writetime after a certain amount of time elapsed since the last input.







      python automation user-inactivity






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 13:45







      carlWheezer

















      asked Mar 8 at 9:36









      carlWheezercarlWheezer

      315




      315




      closed as too broad by Marcin Orlowski, stovfl, thewaywewere, Deadpool, mao Mar 8 at 19:29


      Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









      closed as too broad by Marcin Orlowski, stovfl, thewaywewere, Deadpool, mao Mar 8 at 19:29


      Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
























          3 Answers
          3






          active

          oldest

          votes


















          1














          pynput looks like it might be for you. See docs



          It would be something like



          from pynput import mouse
          with mouse.Listener(on_click=reset_timer,
          on_move=reset_timer,
          on_scroll=reset_timer) as listener:
          begin_timer()





          share|improve this answer






























            0














            Another way might be to set your monitor screen off (screen saver options) after 5 minutes and then write a script which detects the monitor state.



            Here is an example on how to do this:
            How to check whether the device's display is turned on/off with Python?



            Happy coding






            share|improve this answer






























              0














              It may not be the cleanest solution but since I am a novice Python programmer I am pretty happy with it.
              import datetime
              from ctypes import Structure, windll, c_uint, sizeof, byref
              import time



              class LASTINPUTINFO(Structure):
              _fields_ = [
              ('cbSize', c_uint),
              ('dwTime', c_uint),
              ]


              def get_idle_duration():
              lastInputInfo = LASTINPUTINFO()
              lastInputInfo.cbSize = sizeof(lastInputInfo)
              windll.user32.GetLastInputInfo(byref(lastInputInfo))
              millis = windll.kernel32.GetTickCount() - lastInputInfo.dwTime
              return millis / 1000.0


              while 1:
              GetLastInputInfo = int(get_idle_duration())

              if GetLastInputInfo >= 10:
              start = time.time()
              startTime = datetime.datetime.now()

              while GetLastInputInfo >= 10:
              GetLastInputInfo = int(get_idle_duration())
              if GetLastInputInfo < 10:
              end = time.time()
              time_elapsed = end - start + 10
              if time_elapsed >= 10:
              with open("C:\Users\[USER]\Desktop\time.txt", 'w') as f:
              f.write('Pause from ' + str(startTime) + ' to ' + str(
              datetime.datetime.now()) + 'nDuration: ' + str(time_elapsed))


              For testing purposes, I set the time to be marked as absent to 10 seconds. So if you want to make something similar just make sure to change all the 10's to the wished time in seconds






              share|improve this answer































                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                1














                pynput looks like it might be for you. See docs



                It would be something like



                from pynput import mouse
                with mouse.Listener(on_click=reset_timer,
                on_move=reset_timer,
                on_scroll=reset_timer) as listener:
                begin_timer()





                share|improve this answer



























                  1














                  pynput looks like it might be for you. See docs



                  It would be something like



                  from pynput import mouse
                  with mouse.Listener(on_click=reset_timer,
                  on_move=reset_timer,
                  on_scroll=reset_timer) as listener:
                  begin_timer()





                  share|improve this answer

























                    1












                    1








                    1







                    pynput looks like it might be for you. See docs



                    It would be something like



                    from pynput import mouse
                    with mouse.Listener(on_click=reset_timer,
                    on_move=reset_timer,
                    on_scroll=reset_timer) as listener:
                    begin_timer()





                    share|improve this answer













                    pynput looks like it might be for you. See docs



                    It would be something like



                    from pynput import mouse
                    with mouse.Listener(on_click=reset_timer,
                    on_move=reset_timer,
                    on_scroll=reset_timer) as listener:
                    begin_timer()






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 8 at 9:46









                    Charles LandauCharles Landau

                    2,8011317




                    2,8011317























                        0














                        Another way might be to set your monitor screen off (screen saver options) after 5 minutes and then write a script which detects the monitor state.



                        Here is an example on how to do this:
                        How to check whether the device's display is turned on/off with Python?



                        Happy coding






                        share|improve this answer



























                          0














                          Another way might be to set your monitor screen off (screen saver options) after 5 minutes and then write a script which detects the monitor state.



                          Here is an example on how to do this:
                          How to check whether the device's display is turned on/off with Python?



                          Happy coding






                          share|improve this answer

























                            0












                            0








                            0







                            Another way might be to set your monitor screen off (screen saver options) after 5 minutes and then write a script which detects the monitor state.



                            Here is an example on how to do this:
                            How to check whether the device's display is turned on/off with Python?



                            Happy coding






                            share|improve this answer













                            Another way might be to set your monitor screen off (screen saver options) after 5 minutes and then write a script which detects the monitor state.



                            Here is an example on how to do this:
                            How to check whether the device's display is turned on/off with Python?



                            Happy coding







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 8 at 10:15









                            Richard LenkiewiczRichard Lenkiewicz

                            594




                            594





















                                0














                                It may not be the cleanest solution but since I am a novice Python programmer I am pretty happy with it.
                                import datetime
                                from ctypes import Structure, windll, c_uint, sizeof, byref
                                import time



                                class LASTINPUTINFO(Structure):
                                _fields_ = [
                                ('cbSize', c_uint),
                                ('dwTime', c_uint),
                                ]


                                def get_idle_duration():
                                lastInputInfo = LASTINPUTINFO()
                                lastInputInfo.cbSize = sizeof(lastInputInfo)
                                windll.user32.GetLastInputInfo(byref(lastInputInfo))
                                millis = windll.kernel32.GetTickCount() - lastInputInfo.dwTime
                                return millis / 1000.0


                                while 1:
                                GetLastInputInfo = int(get_idle_duration())

                                if GetLastInputInfo >= 10:
                                start = time.time()
                                startTime = datetime.datetime.now()

                                while GetLastInputInfo >= 10:
                                GetLastInputInfo = int(get_idle_duration())
                                if GetLastInputInfo < 10:
                                end = time.time()
                                time_elapsed = end - start + 10
                                if time_elapsed >= 10:
                                with open("C:\Users\[USER]\Desktop\time.txt", 'w') as f:
                                f.write('Pause from ' + str(startTime) + ' to ' + str(
                                datetime.datetime.now()) + 'nDuration: ' + str(time_elapsed))


                                For testing purposes, I set the time to be marked as absent to 10 seconds. So if you want to make something similar just make sure to change all the 10's to the wished time in seconds






                                share|improve this answer





























                                  0














                                  It may not be the cleanest solution but since I am a novice Python programmer I am pretty happy with it.
                                  import datetime
                                  from ctypes import Structure, windll, c_uint, sizeof, byref
                                  import time



                                  class LASTINPUTINFO(Structure):
                                  _fields_ = [
                                  ('cbSize', c_uint),
                                  ('dwTime', c_uint),
                                  ]


                                  def get_idle_duration():
                                  lastInputInfo = LASTINPUTINFO()
                                  lastInputInfo.cbSize = sizeof(lastInputInfo)
                                  windll.user32.GetLastInputInfo(byref(lastInputInfo))
                                  millis = windll.kernel32.GetTickCount() - lastInputInfo.dwTime
                                  return millis / 1000.0


                                  while 1:
                                  GetLastInputInfo = int(get_idle_duration())

                                  if GetLastInputInfo >= 10:
                                  start = time.time()
                                  startTime = datetime.datetime.now()

                                  while GetLastInputInfo >= 10:
                                  GetLastInputInfo = int(get_idle_duration())
                                  if GetLastInputInfo < 10:
                                  end = time.time()
                                  time_elapsed = end - start + 10
                                  if time_elapsed >= 10:
                                  with open("C:\Users\[USER]\Desktop\time.txt", 'w') as f:
                                  f.write('Pause from ' + str(startTime) + ' to ' + str(
                                  datetime.datetime.now()) + 'nDuration: ' + str(time_elapsed))


                                  For testing purposes, I set the time to be marked as absent to 10 seconds. So if you want to make something similar just make sure to change all the 10's to the wished time in seconds






                                  share|improve this answer



























                                    0












                                    0








                                    0







                                    It may not be the cleanest solution but since I am a novice Python programmer I am pretty happy with it.
                                    import datetime
                                    from ctypes import Structure, windll, c_uint, sizeof, byref
                                    import time



                                    class LASTINPUTINFO(Structure):
                                    _fields_ = [
                                    ('cbSize', c_uint),
                                    ('dwTime', c_uint),
                                    ]


                                    def get_idle_duration():
                                    lastInputInfo = LASTINPUTINFO()
                                    lastInputInfo.cbSize = sizeof(lastInputInfo)
                                    windll.user32.GetLastInputInfo(byref(lastInputInfo))
                                    millis = windll.kernel32.GetTickCount() - lastInputInfo.dwTime
                                    return millis / 1000.0


                                    while 1:
                                    GetLastInputInfo = int(get_idle_duration())

                                    if GetLastInputInfo >= 10:
                                    start = time.time()
                                    startTime = datetime.datetime.now()

                                    while GetLastInputInfo >= 10:
                                    GetLastInputInfo = int(get_idle_duration())
                                    if GetLastInputInfo < 10:
                                    end = time.time()
                                    time_elapsed = end - start + 10
                                    if time_elapsed >= 10:
                                    with open("C:\Users\[USER]\Desktop\time.txt", 'w') as f:
                                    f.write('Pause from ' + str(startTime) + ' to ' + str(
                                    datetime.datetime.now()) + 'nDuration: ' + str(time_elapsed))


                                    For testing purposes, I set the time to be marked as absent to 10 seconds. So if you want to make something similar just make sure to change all the 10's to the wished time in seconds






                                    share|improve this answer















                                    It may not be the cleanest solution but since I am a novice Python programmer I am pretty happy with it.
                                    import datetime
                                    from ctypes import Structure, windll, c_uint, sizeof, byref
                                    import time



                                    class LASTINPUTINFO(Structure):
                                    _fields_ = [
                                    ('cbSize', c_uint),
                                    ('dwTime', c_uint),
                                    ]


                                    def get_idle_duration():
                                    lastInputInfo = LASTINPUTINFO()
                                    lastInputInfo.cbSize = sizeof(lastInputInfo)
                                    windll.user32.GetLastInputInfo(byref(lastInputInfo))
                                    millis = windll.kernel32.GetTickCount() - lastInputInfo.dwTime
                                    return millis / 1000.0


                                    while 1:
                                    GetLastInputInfo = int(get_idle_duration())

                                    if GetLastInputInfo >= 10:
                                    start = time.time()
                                    startTime = datetime.datetime.now()

                                    while GetLastInputInfo >= 10:
                                    GetLastInputInfo = int(get_idle_duration())
                                    if GetLastInputInfo < 10:
                                    end = time.time()
                                    time_elapsed = end - start + 10
                                    if time_elapsed >= 10:
                                    with open("C:\Users\[USER]\Desktop\time.txt", 'w') as f:
                                    f.write('Pause from ' + str(startTime) + ' to ' + str(
                                    datetime.datetime.now()) + 'nDuration: ' + str(time_elapsed))


                                    For testing purposes, I set the time to be marked as absent to 10 seconds. So if you want to make something similar just make sure to change all the 10's to the wished time in seconds







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Mar 9 at 10:13

























                                    answered Mar 8 at 13:49









                                    carlWheezercarlWheezer

                                    315




                                    315













                                        Popular posts from this blog

                                        Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                                        Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                                        Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved