【问题标题】:AutoHotkey GetWinTitle when current window changes当前窗口更改时的 AutoHotkey GetWinTitle
【发布时间】:2017-03-17 21:20:25
【问题描述】:

我正在尝试制作一个 ahk 脚本,当新窗口打开(或重新聚焦)时会提醒您。换句话说,我希望它检测当前窗口何时发生变化。我尝试比较窗口名称以检测差异:

    0::
    WinGetTitle, title, A
    windowTitle=%title%
    MsgBox, "The current window is %title%."
    return

    9::
    WinGetTitle, title2, A
    if (%title2% = %title%)
    {
        success=1
    }
    else
    {
        MsgBox, "The current window changed to %title2%."
    }
    return

但是,
1) 我显然在变量中使用了非法字符;和
2)我宁愿使用与此不同的方法;

提前致谢!

我希望警报包含当前窗口的名称。

【问题讨论】:

  • 在if 中使用括号时,不要使用%,因为变量已经自动展开了。
  • 哇!有效!当我阅读错误消息时,我看着我,好像我不能在变量中使用引号。谢谢!

标签: automation autohotkey


【解决方案1】:
CurrentTitle := ""

SetTimer, CheckWindow, 1000
return

CheckWindow:
    WinGetTitle, NewTitle, A
    if (CurrentTitle != NewTitle){
        ToolTip % "Window changed to: " NewTitle
        CurrentTitle := NewTitle
    }
    return

【讨论】:

  • 我更喜欢使用setTimer,所以脚本执行不会阻塞
  • @Blauhirn - 更新为使用 SetTimer
猜你喜欢
  • 2018-02-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-02
  • 1970-01-01
  • 2013-09-09
  • 1970-01-01
  • 2015-11-21
相关资源
最近更新 更多