美文网首页
python 实现弹窗拦截

python 实现弹窗拦截

作者: 时尚灬IT男 | 来源:发表于2018-08-10 12:18 被阅读346次

原理:

这里实现的弹窗拦截,是程序不断的监视电脑屏幕,当出现需要拦截的窗口时,自动控制屏幕点击事件关闭。

第一步:将需要关闭弹窗的点击位置截图。

第二步:直接上代码

while True:

#获取图片的相对屏幕的中心点坐标

    # location = pyautogui.locateCenterOnScreen('close.PNG')

#获取图片在屏幕的位置及大小

    location=pyautogui.locateOnScreen('close1.PNG')

    if location != None:

        print(location)

        x1,y1,x2,y2 = location

        print(x1,y1,x2,y2)

#记录鼠标的位置

        x3, y3 = pyautogui.position()

#计算出需要点击的位置坐标

        pyautogui.click(x1+x2-25, y1+y2/2, button='left')

将鼠标的位置回到开始位置

        pyautogui.moveTo(x3, y3)

这样就实现了一个自己定制的拦截弹窗。

补充:

根据这个原理可以做更多电脑自动化工具。

相关文章

网友评论

      本文标题:python 实现弹窗拦截

      本文链接:https://www.haomeiwen.com/subject/znjkbftx.html