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;
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
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.
add a comment |
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
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.
add a comment |
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
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
python automation user-inactivity
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.
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
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()
add a comment |
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
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()
add a comment |
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()
add a comment |
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()
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()
answered Mar 8 at 9:46
Charles LandauCharles Landau
2,8011317
2,8011317
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Mar 8 at 10:15
Richard LenkiewiczRichard Lenkiewicz
594
594
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
edited Mar 9 at 10:13
answered Mar 8 at 13:49
carlWheezercarlWheezer
315
315
add a comment |
add a comment |