def set_mouse_position(show_log):
    """
    Threaded function which sets the mouse position on receiving the "event_switch" event
    from the keyboard event handler. Will exit if it recieves the "event_quit" event.

    @param args tuple: Only first value is used - bool, enables/disables debug log
    """

    global event_switch, event_quit
    current_win = ''
    previous_win = ''

    # Runs as long as "event_quit" has not been received
    while not event_quit.is_set():
        if event_switch.is_set():
            # Wait for the 'Task Switching' window to close
            while(GetWindowText(GetForegroundWindow()).split('-')[-1] == 'Task Switching'):
                pass
            time.sleep(0.25)

            # Get the foreground window's text again
            current_win = GetWindowText(GetForegroundWindow())

            # Make sure we didn't end up with the same window as before
            if current_win != previous_win:
                # Get the foreground window's dimensions
                l, t, r, b = GetWindowRect(GetForegroundWindow())

                # Calculate mouse position
                x = l + (r - l) / 2
                y = t + (b - t) / 2

                # Print the window information and new mouse co-ordinates
                if(show_log):
                    print 'Window: ', current_win.split('-')[-1], ' @[', l, t, r, b, ']'
                    print 'Setting mouse position to: (', x, ', ', y, ')'
                    print '---\n'

                # Set the new mouse position
                SetCursorPos((x, y))

                # Set the previous window to the current window
                previous_win = current_win

            # Clear "event_switch" event
            event_switch.clear()
def degital():
    """the function for calcultion and identification of the  which is currently opened window and its time"""
    infoObj = {}
    closedObj = {}
    openedWindowObj = {}
    WindowOTime = ""
    WindowCTime = ""

    def openedTime():
        #function for finding opened time
        global WindowOTime
        WindowOTime = datetime.datetime.now().strftime("%H-%M-%S")
        return WindowOTime

    def closedTime():
        # function for finding closed time
        global WindowCTime
        WindowCTime = datetime.datetime.now().strftime("%H-%M-%S")
        return WindowCTime

    try:
        while True:
            #actual process starts here....
            openedWindow = GetWindowText(GetForegroundWindow())
            currentWindow = openedWindow.split("-")[-1]
            if GetForegroundWindow():
                if currentWindow not in infoObj:
                    print("true")
                    oo = openedTime()
                    infoObj[currentWindow] = oo
                    openedWindowObj[currentWindow] = oo
                    blood = [currentWindow]

                else:
                    pass

                if currentWindow != blood[0]:
                    clo = closedTime()
                    closedObj[blood[0]] = clo

                else:
                    pass

    except KeyboardInterrupt as e:
        if "" in openedWindowObj:
            openedWindowObj.pop('')
        if ' Visual Studio Code' in openedWindowObj:
            del openedWindowObj[' Visual Studio Code']
        for key, value in openedWindowObj.items():
            totaltime = value.split("-")
            a = int(totaltime[0])
            b = int(totaltime[1])
            c = int(totaltime[2])
            for kk, vv in closedObj.items():
                totaltime1 = vv.split("-")
                a2 = int(totaltime1[0])
                b2 = int(totaltime1[1])
                c2 = int(totaltime1[2])
                x = str(a - a2)
                y = str(b - b2)
                z = str(c - c2)
                z1 = x.replace("-", "")
                z2 = y.replace("-", "")
                z3 = z.replace("-", "")
            print(
                f"you used { key}  for  { z1}Hours  {z2}Minutes and { z3}seconds"
            )

            if int(z1) >= 1:
                notification.notify(
                    title="Time to take Rest",
                    message=
                    f"you are using {key} from   { z1}Hours   {z2}Minutes  and   { z3}seconds pls take rest",
                    timeout=8)

        batt = battery.status
        for keyB, valueB in batt.items():
            print(keyB, valueB)
Beispiel #3
0
def checkWindow():
    path = GetWindowText(GetForegroundWindow())
    return path.split('\\')[-1]