【问题标题】:Autohotkey window appear event自动热键窗口出现事件
【发布时间】:2012-02-28 21:51:09
【问题描述】:

我正在使用 WorkRave 休息提醒,并希望在出现休息窗口时关闭我的屏幕。 我知道如何关闭它。

出现指定窗口(#IfWinActive ahk_class ...)时如何创建事件?

另外,我可以绑定 % 符号吗? {%} 不起作用,而不是其他的。

【问题讨论】:

  • Romale,当这个 WorkRave 休息提醒处于活动状态时,你能打开 windows spy 吗?您可以通过右键单击 AHK 图标来打开 Windows Spy。 Window Spy 将始终处于最重要的位置。当您激活 WorkRave 屏幕时,您应该会看到详细信息(包括 ahk_class)。我不知道你想用 % 符号做什么。
  • Romale,到目前为止运气好吗?
  • 1. Windows spy 无法捕捉到 workrave 的第一个保持在最前面的警告。但我已经通过窗口列表(ahk_class)抓住了它。我如何绑定一个动作,当它出现时? 2. 示例,无效:5::{%} %::{5}

标签: autohotkey


【解决方案1】:

要立即通知出现的窗口,请使用 Shell Hook。这有时非常快,以至于自动热键甚至在您自己看到窗口之前就做出反应。

AutoHotkey Forum 上演示了一个 shell 挂钩。

您的用法示例(几乎从论坛帖子中逐字复制):

#Persistent
SetBatchLines, -1
Process, Priority,, High

Gui +LastFound
hWnd := WinExist()

DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
Return

ShellMessage( wParam,lParam )
{
    If ( wParam = 1 ) ;  HSHELL_WINDOWCREATED := 1
    {
        WinGetTitle, Title, ahk_id %lParam%
        If  ( Title = "WorkRest" )
            WinClose, ahk_id %lParam% ; close it immideately
    }
}

如果您想在命令中使用文字 % 符号,请使用 AutoHotkey 的转义字符、反引号 `(与美式键盘上的 ~ 在同一键上)将其转义,如下所示:

MsgBox You are 200`% awesome!

【讨论】:

  • 这太棒了,效果很好!也看看this answer。你能设计你的脚本来做到这一点吗? IE。也检测所有现有的窗口,看看以前是否见过?
  • 这在短时间内打开两个窗口时不起作用。你也有解决方案吗?
  • @botenvouwer 如果您错过了活动,您可能需要很长时间才能处理上一个活动。关键是下一个ShellMessage要等上一个完成后才能运行,但是ShellMessage可以打断其他代码。所以更改 ShellMessage 将消息数据添加到全局队列对象并立即返回,然后在单独的循环/计时器中处理消息队列,以执行您的窗口/GUI/鼠标/键盘等相对较慢的命令。
  • @Vijay 查看WinGet, List 以列出窗口。
【解决方案2】:

罗马,

你可以试试这个,但由于我不使用 WorkRave,所以无法测试。

; This next line needs to be added at the top of the AHK file, so it will be started as soon as AHK starts.
; Every 120000 ms, it will launch the "WorkRave:" script to check if a window with WorkRave exists.
SetTimer, WorkRave,120000 ; Run WorkRaveTester every 2 minutes = 120000


; Somewhere else in the AHK file.....
WorkRave: ; This is the label for the WorkRave script
SetTitleMatchMode, 2 ; 2 = Matches the string WorkRave anywhere in the window title of IfWinExist
IfWinExist, WorkRave ; When WorkRave window exists
{
  TrayTip, WorkRave, Started ,1 ; Or whatever you want to do here....
}
Return

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多