2012-02-07 116 views
6

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

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

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

+0

Romale,当此WorkRave休息提醒处于活动状态时,您可以打开窗户间谍吗?通过右键单击AHK图标打开Windows Spy。窗户间谍将永远在顶部。当您激活WorkRave屏幕时,您应该看到详细信息(包括ahk_class)。我不知道你想用%符号做什么。 – 2012-02-07 16:33:34

+0

Romale,到目前为止运气如何? – 2012-02-08 17:50:33

+0

1. Windows间谍无法抓到workrave的第一个留在最高警告。但我通过窗口列表(ahk_class)捕获它。我怎样才能绑定一个行动,当它出现? 2.示例,不起作用: 5 :: {%} %:: {5} – 2012-02-09 10:45:30

回答

8

要立即通知出现窗口,请使用Shell挂钩。有时这个速度非常快,以至于在您自己看到窗户之前,autohotkey会作出反应。

一个外壳挂钩在AutoHotkey Forum上显示。

与您的使用情况(几乎是从论坛帖子逐字复制)的一个例子:

#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! 
+0

这太棒了,效果很棒!看看[这个答案](http://superuser.com/a/266240/16847)。你能设计你的脚本来做到这一点吗?即检测所有现有的窗口,看看以前是否看过? – Vijay 2014-04-23 09:01:37

0

Romale,

你可以试试这个,但因为我不使用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