ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

AHK 通过鼠标关闭指定窗口

2020-03-09 18:03:59  阅读:453  来源: 互联网

标签:窗口 鼠标 AHK id classname window ahk return IDC


有时候程序无响应, 调出程序管理器又很麻烦, 所以写了这个脚本.

#SingleInstance Force

;; File Name: Close_window_by_click.ahk
;; Author:    https://www.cnblogs.com/codworm
;; Source:    https://autohotkey.com/board/topic/32608-changing-the-system-cursor

;;; Usage
;;  1. 运行脚本可绑定热键或者通过Listary之类的启动器.
;;  2. 运行脚本之后再把鼠标移动到窗口点击鼠标左键即可关闭窗口.

IDC_ARROW       := 32512
IDC_IBEAM       := 32513
IDC_WAIT        := 32514
IDC_CROSS       := 32515
IDC_UPARROW     := 32516
IDC_SIZE        := 32640
IDC_ICON        := 32641
IDC_SIZENWSE    := 32642
IDC_SIZENESW    := 32643
IDC_SIZEWE      := 32644
IDC_SIZENS      := 32645
IDC_SIZEALL     := 32646
IDC_NO          := 32648
IDC_HAND        := 32649
IDC_APPSTARTING := 32650
IDC_HELP        := 32651

SetTimer, Timer, 300
Return

Timer:
    MouseGetPos, x1, y1
    Sleep, 500
    MouseGetPos, x2, y2

    If ((x1<>x2) or (y1<>y2)) {
        MouseGetPos,,, id
        WinGetClass, classname, ahk_id %id%

        If (is_cursor_inside_window(classname)) {
            SetSystemCursor()
            ToolTip, %classname%, 100, 100
        } else {
            RestoreCursors()
            ToolTip, "NOT valid window", 0, 0
        }
    }
return

is_cursor_inside_window(classname) {
    if (!classname) {
        return false
    }

    if classname not in DV2ControlHost,WorkerW,Shell_TrayWnd,UltraMonDeskTaskBar,Progman,Shell_TrayWnd,NotifyIconOverflowWindow,Windows.UI.Core.CoreWindow
        WinGetPos, X, Y, Width, Height, ahk_class %classname%

    if (X and Y and Width and Height and (X != 0) and (Y != 0) and (Width !=0) and (Height !=0))
        return true

    return false
}

SetSystemCursor() {
    IDC_SIZEALL := 32651
    CursorHandle := DllCall( "LoadCursor", Uint, 0, Int, IDC_SIZEALL)

    Cursors = 32512,32513,32514,32515,32516,32640,32641,32642,32643,32644,32645,32646,32648,32649,32650,32651
    Loop, Parse, Cursors, `,
    {
        DllCall("SetSystemCursor", Uint, CursorHandle, Int, A_LoopField)
    }
}

RestoreCursors() {
    SPI_SETCURSORS := 0x57
    DllCall( "SystemParametersInfo", UInt, SPI_SETCURSORS, UInt, 0, UInt, 0, UInt, 0)
}

close_window() {
    MouseGetPos,,, id
    WinGetClass, classname, ahk_id %id%

    WinClose, ahk_id %id%
}

~LButton::
    If (is_cursor_inside_window(classname)) {
        close_window()
    }
    RestoreCursors()
    ExitApp
return

esc::exitapp

标签:窗口,鼠标,AHK,id,classname,window,ahk,return,IDC
来源: https://www.cnblogs.com/codworm/p/12450054.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有