首页 > 编程语言 > 详细

[python 学习]躲窗口

时间:2019-09-14 23:51:20      阅读:157      评论:0      收藏:0      [点我收藏+]
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

[python 学习]躲窗口

原文:https://www.cnblogs.com/cyber-shady/p/11520439.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!