Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import threading
- import time
- import tkinter as tk
- from tkinter import ttk
- import pyautogui
- import win32api
- active = False
- thread1 = threading.Thread()
- def getIdleTime():
- return int((win32api.GetTickCount() - win32api.GetLastInputInfo()) / 1000.0)
- def toggle():
- global active
- global thread1
- active = not active
- if active:
- btn.config(text='Disable')
- thread1 = threading.Thread(target=inactive_loop)
- thread1.start()
- else:
- btn.config(text='Enable')
- lbl.config(text='Press \'Enable\' to start')
- def on_closing():
- global active
- active = False
- window.destroy()
- def inactive_loop():
- while active:
- idle = getIdleTime()
- timeout = 45
- if timeout - idle >= 0:
- lbl.config(text='Sending input in {0:3d}s'.format(int(timeout - idle)))
- if idle > timeout:
- pyautogui.press('insert')
- pyautogui.press('insert')
- else:
- time.sleep(1)
- if __name__ == '__main__':
- window = tk.Tk()
- s = ttk.Style()
- s.theme_use('vista')
- window.protocol("WM_DELETE_WINDOW", on_closing)
- window.title("Presenting ever present presence")
- window.geometry('350x50+0+0')
- lbl = ttk.Label(window, text="Press 'Enable' to start")
- lbl.grid(column=0, row=0)
- btn = ttk.Button(window, text="Enable", command=toggle)
- btn.grid(column=0, row=1)
- window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement