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('在窗口中')
'''
实现更改当前窗口位置
对任务管理器无效
'''
win32gui.SetWindowPos(hwnd, None, 100, 0, 600, 400, win32con.SWP_NOSENDCHANGING|win32con.SWP_SHOWWINDOW)
time.sleep(0.5)
except:
pass