from win32gui import GetWindowText, GetForegroundWindow
import time, win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
time.sleep(3)
t = GetWindowText(GetForegroundWindow())
time.sleep(0.1)
if 'YouTube' in t:
shell.SendKeys("^+W")
print(t)