Detect which Taskbar button was clicked (identify target window)

痴心易碎 提交于 2019-12-10 10:05:12

问题


I am trying to figure out how to detect which Taskbar button was clicked. Specifically, I want to write a script that makes it possible to maximize a window by double-clicking its Taskbar button. That requires knowing which Taskbar button was clicked, which I am having a difficult time finding any leads on.

Does anyone know how this can be accomplished?


回答1:


That's a though one I have to admit. I can't offer you a best practice solution, but here is a little work around, maybe that enough for your purposes:

CoordMode, Mouse, Screen
~LButton:: 
    If (A_TimeSincePriorHotkey<400) and (A_PriorHotkey="~LButton") {
        WinGetPos, taskBarX, taskBarY, taskBarW, taskBarH, ahk_class Shell_TrayWnd
        MouseGetPos, mouseX, mouseY
        If (mouseX >= taskBarX && mouseY >= taskBarY && mouseX <= taskBarX+taskBarW && mouseY <= taskBarY+taskBarH)
            OnDoubleClickTaskbar()
    }
Return

OnDoubleClickTaskbar() {
    ;WinWaitNotActive, ahk_class Shell_TrayWnd
    Sleep, 200
    WinMaximize, A
}

Tested on Windows 8.1.



来源:https://stackoverflow.com/questions/31375455/detect-which-taskbar-button-was-clicked-identify-target-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!