I wanted to write a time tracking software using python for windows. How do I approach finding the total screen time of individual applications? Is there any windows service which tracks the total on screen time spent by a particular application during its current session? Or is there some other approach which could be used?
Asked
Active
Viewed 1,946 times
3
-
Find some open source ones and see for yourself. They could infer usage from the title and other properties of the focused window. – ChrisGPT was on strike Mar 02 '19 at 17:14
-
Time managed how? Clock time? CPU time? – user3344003 Mar 02 '19 at 17:25
1 Answers
2
maybe pywin32 is what you looking for:
from win32gui import GetWindowText, GetForegroundWindow
print(GetWindowText(GetForegroundWindow()))
you have to run in repeatedly in the background and calculate the total screen time by yourself.

stefan
- 188
- 1
- 7
-
I didn't know about this module. It looks like a good solution to my problem. Thanks! – Tarun Khare Mar 02 '19 at 18:38
-
Just a follow up question, how you will get application name for cases like 'This PC' where title of the window is usually the current directory we are in, and not the application name. I wanted to only get 'This PC' as output and NOT 'Local disk (D:)' or something else – Tarun Khare Mar 03 '19 at 20:18
-
1with a little workaround you can get the process name of the foreground window, therefore you also need `psutil` to get the process name based on a PID, the PID you can get with `GetWindowThreadIdProcessId`. `psutil.Process(win32process.GetWindowThreadProcessId(GetForegroundWindow())[1]).name` – stefan Mar 03 '19 at 20:56