Advertisement
Guest User

present.pyw

a guest
May 25th, 2023
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.48 KB | Source Code | 0 0
  1. #!/usr/bin/env python
  2. import threading
  3. import time
  4. import tkinter as tk
  5. from tkinter import ttk
  6. import pyautogui
  7. import win32api
  8.  
  9. active = False
  10. thread1 = threading.Thread()
  11.  
  12.  
  13. def getIdleTime():
  14.     return int((win32api.GetTickCount() - win32api.GetLastInputInfo()) / 1000.0)
  15.  
  16.  
  17. def toggle():
  18.     global active
  19.     global thread1
  20.     active = not active
  21.     if active:
  22.         btn.config(text='Disable')
  23.         thread1 = threading.Thread(target=inactive_loop)
  24.         thread1.start()
  25.     else:
  26.         btn.config(text='Enable')
  27.         lbl.config(text='Press \'Enable\' to start')
  28.  
  29.  
  30. def on_closing():
  31.     global active
  32.     active = False
  33.     window.destroy()
  34.  
  35.  
  36. def inactive_loop():
  37.     while active:
  38.         idle = getIdleTime()
  39.         timeout = 45
  40.  
  41.         if timeout - idle >= 0:
  42.             lbl.config(text='Sending input in {0:3d}s'.format(int(timeout - idle)))
  43.  
  44.         if idle > timeout:
  45.             pyautogui.press('insert')
  46.             pyautogui.press('insert')
  47.         else:
  48.             time.sleep(1)
  49.  
  50.  
  51. if __name__ == '__main__':
  52.     window = tk.Tk()
  53.     s = ttk.Style()
  54.     s.theme_use('vista')
  55.     window.protocol("WM_DELETE_WINDOW", on_closing)
  56.     window.title("Presenting ever present presence")
  57.     window.geometry('350x50+0+0')
  58.     lbl = ttk.Label(window, text="Press 'Enable' to start")
  59.     lbl.grid(column=0, row=0)
  60.     btn = ttk.Button(window, text="Enable", command=toggle)
  61.     btn.grid(column=0, row=1)
  62.     window.mainloop()
  63.  
  64.  
  65.  
  66.  
  67.  
Tags: DevRant
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement