Autohotkey 窗口出现事件 [英] Autohotkey window appear event

查看:35
本文介绍了Autohotkey 窗口出现事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

解决方案

要获得出现窗口的即时通知,请使用 Shell Hook.这有时太快了,自动热键甚至可以在您自己看到窗口之前做出反应.

AutoHotkey 论坛上演示了一个 shell 钩子.>

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

#PersistentSetBatchLines,-1进程、优先级、、高Gui +LastFoundhWnd := WinExist()DllCall( "RegisterShellHookWindow", UInt,hWnd )MsgNum := DllCall("RegisterWindowMessage", Str,"SHELLHOOK")OnMessage(MsgNum, "ShellMessage")返回ShellMessage( wParam,lParam ){如果 (wParam = 1) ;HSHELL_WINDOWCREATED := 1{WinGetTitle,标题,ahk_id %lParam%如果(标题=工作休息")WinClose, ahk_id %lParam% ;立即关闭}}

如果您想在命令中使用文字 % 符号,请使用 AutoHotkey 的转义字符转义它,反引号 `(与美国键盘上的 ~ 在同一键上)像这样:

MsgBox 你是 200`% 真棒!

I'm using WorkRave rest reminder and want to turn off my screen when the rest window appears. I know how to turn it off.

How create an event when specified window (#IfWinActive ahk_class ...) appears?

Also, can i bind % symbol? {%} doesn't work, instead of other ones.

解决方案

To have an instant notification of a window appearing, use a Shell Hook. This is sometimes so fast that autohotkey can react before you even see the window yourself.

A shell hook is demonstrated on the AutoHotkey Forum.

An example with your usage (almost copied verbatim from the forum post):

#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
    }
}

If you want to use a literal % symbol in a command, escape it with AutoHotkey's escape character, the backtick ` (on the same key as ~ on a US keyboard) like so:

MsgBox You are 200`% awesome!

这篇关于Autohotkey 窗口出现事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆