[python 学习]躲窗口
import win32gui import win32api,win32con import time ''' 需要执行下面命令 pip install pywin32 ''' # 获取屏幕宽高 screen_width=win32api.GetSystemMetrics(win32con.SM_CXFULLSCREEN) screen_height=win32api.GetSystemMetrics(win32con.SM_CYFULLSCREEN) print(screen_width,screen_height) while True: try: #获取当前窗口句柄 hwnd = win32gui.GetForegroundWindow() # print(hwnd) #获取当前窗口坐标 left,top,right,bottom=win32gui.GetWindowRect(hwnd) print(left,top,right,bottom) # 获取鼠标位置 cursor_x,cursor_y=win32gui.GetCursorPos() print(cursor_x,cursor_y) if left<=cursor_x and cursor_x<=right and top<=cursor_y and cursor_y<=bottom: print('在窗口中')