Skip to content

Instantly share code, notes, and snippets.

@zztalker
Created December 13, 2020 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zztalker/5fefe550a6e669dd39c5c71daa844e11 to your computer and use it in GitHub Desktop.
Save zztalker/5fefe550a6e669dd39c5c71daa844e11 to your computer and use it in GitHub Desktop.
import time
import win32gui as w
import win32con as wc
import win32process as wp
TRACK_MODE, RESTRICT_MODE = "TRACK", "RESTRICT"
while True:
handle = w.GetForegroundWindow()
w_name = w.GetwindowText(handle)
t_id, p_id = wp.GetWindowThreadProcessId(handle)
print(handle, w_name, t_id, p_id)
time.sleep(1)
# to kill window
mode = get_mode()
# if mode == RESTRICT_MODE and
# w.PostMessage(handle,win32con.WM_CLOSE,0,0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment