AHK 通过鼠标关闭指定窗口

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

#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
上一篇:Arthas(阿尔萨斯)强大定位线程问题


下一篇:Tensor基本理论