【问题标题】:Autohotkey Window-ID自动热键窗口 ID
【发布时间】:2016-03-27 01:00:06
【问题描述】:

谁能帮帮我,我拿了一个脚本并用 cmets 修改了我不需要的部分。现在我想稍微改变一下脚本的工作方式。

Alt+4 在弹出窗口中发布活动窗口的 WIndow-ID

Alt+3 将编辑器置于前面/焦点

Alt+2 将 Internet Explorer 置于前面/焦点

现在我希望 IE 和编辑器不会因为那里的名称而成为焦点,我希望它们因为那里的 Window-ID 而成为焦点。

我该怎么做?那可能吗?在文档中,我找不到通过 ifwinaktive Doku 输入 ID 的可能性

!4::
WinGet, active_id, ID, A
MsgBox, The active window's ID is "%active_id%".
return

!3::ToggleWindow("Editor")
!2::ToggleWindow("Internet")


ToggleWindow(TheWindowTitle)
{
    SetTitleMatchMode,2
    DetectHiddenWindows, Off
    IfWinActive, %TheWindowTitle%
    {
       ;;;;; WinMinimize, %TheWindowTitle%
    }
    Else
    {
        IfWinExist, %TheWindowTitle%
        {
            WinActivate
            ;;;;; Tried using WinMaximize/WinRestore here but same result
        }
        Else
        {
            ;;;;; DetectHiddenWindows, On
            ;;;;; IfWinExist, %TheWindowTitle%
            ;;;;; {
            ;;;;;     WinShow
            ;;;;;     WinActivate
            ;;;;; }
        }
    }
}

【问题讨论】:

    标签: autohotkey


    【解决方案1】:

    希望我能正确理解您的问题:您想在不同的进程 ID 上使用 ifWinActive

    有几种方法可以确定您的窗口。另请参阅WinTitle 以供参考。我要复制一些我曾经给我的朋友发过的短信。

    WinTitle 参数通常不会改变:

    ; ahk_class does not change after program restart
    ; find out the ahk_class name with WindowSpy
    ifWinActive, ahk_class Notepad
        msgBox
    
    ; process name usually does not change.
    ; find it out using TaskManager or winGet
    ifWinActive, ahk_exe Notepad.exe
        msgBox
    

    可能会不时改变的WinTitle参数:

    ; the TITLE of the window, like "Editor" or "google.com".
    ; find it out using your eyes.
    ifWinActive, Editor
        msgBox
    
    ; window TEXT.
    ; find it out using WindowSpy
    setTitleMatchMode, slow
    ifWinActive,, hi. some text which I typed in the editor
        msgBox
    setTitleMatchMode, fast
    ; Note: you can also make use of ExcludeTitle and ExcludeText. see ifWinActive
    

    WinTitle 参数在相应程序重新启动后肯定会发生变化:

    注意:要清楚地识别窗口,其中一种方法将是您的首选方法。每个正在运行的进程只有一个 ID/PID。

    ; unique ID / HWND does change, you'll have to retrieve it with something stable:
    winGet, editor_hwnd, ID, ahk_class Notepad
    ifWinActive, ahk_id %editor_hwnd%
        msgBox
    
    ; process ID also varies:
    winGet, editor_pid, PID, ahk_class Notepad
    ifWinActive, ahk_pid %editor_pid%
        msgBox
    

    所以,在你的例子中,你可以使用

    !3::ToggleWindow("ahk_class Notepad")
    

    或使用上述示例之一。

    【讨论】:

    • 太酷了!请考虑回答并接受您自己的答案。
    • WinActivate, ahk_id IDhere
    猜你喜欢
    • 2012-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-16
    • 1970-01-01
    相关资源
    最近更新 更多