Want to make code for inactive or idle user time in Python when he did not show any movement on screen and keyboard and mouse through

151 views Asked by At

I am student and I am making an app regarding tracking time activity. So please help me to give an solution. I am finding out from last 4 days regarding the hints or code . I got one solution of my friend . but i am confuse that how to use this. If i use this and store that time so how could i make an object and api so i can display this time in frontend side.

import sys

if sys.platform == 'win32':
    from ctypes import *
    
    class LASTINPUTINFO(Structure):
        _fields_ = [
            ('cbSize', c_uint),
            ('dwTime', c_int),
        ]
        
    def get_idle_duration():
        lastInputInfo = LASTINPUTINFO()
        lastInputInfo.cbSize = sizeof(lastInputInfo)
        if windll.user32.GetLastInputInfo(byref(lastInputInfo)):
            millis = windll.kernel32.GetTickCount() - lastInputInfo.dwTime
            return millis / 1000.0
        else:
            return 0
else:
    def get_idle_duration():
        return 0
        
if __name__ == '__main__':
    import time
    while True:
        duration = get_idle_duration()
        print('User idle for %.2f seconds.' % duration)
        time.sleep(0.5)

I am expecting that please help me to solve my solution. I am student and I am learning this. I am expecting an output like total idle time of computer is 1 hr or 2 hr . I already made code for tracking time for task/project time.

0

There are 0 answers