自动热键窗口出现事件 [英] Autohotkey window appear event

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

问题描述

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

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

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

解决方案

要具有窗口出现的即时通知,请使用Shell Hook.有时速度如此之快,以至于自动热键可以在您自己看到窗口之前就做出反应.

AutoHotkey论坛上演示了一个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!

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!

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

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