自动热键窗口出现事件

问题描述 投票:0回答:3

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

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

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

autohotkey
3个回答
15
投票

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

AutoHotkey 论坛上演示了 shell hook。

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

#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
投票

罗马勒,

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

0
投票
  1. 打开WorkRave
  2. 右键单击 > 首选项 > 用户界面 > 阻止模式:无阻止 > 关闭
  3. 将以下代码另存为 WorkRave Close Rest Reminder Window.ahk
 #NoEnv
    设置工作目录%A_ScriptDir%
    #警告
    坐标模式、鼠标、窗口
    发送模式输入
    #SingleInstance 强制
    设置标题匹配模式 2
    快速设置标题匹配模式
    检测隐藏Windows 关闭
    检测隐藏文本打开
    #WinActivateForce
    #无托盘图标
    设置控制延迟 1
    设置WinDelay 0
    设置按键延迟-1
    设置鼠标延迟-1
    设置批处理线-1
    #执着的
    #MaxThreadsPerHotkey 2

    WorkRave关闭RestReminderWindow:
    环形
    {
        WinWait,休息中断 ahk_class gdkWindowToplevel ahk_exe Workrave.exe
        WinClose,休息休息 ahk_class gdkWindowToplevel ahk_exe Workrave.exe
        运行,关闭屏幕
    }
    返回
© www.soinside.com 2019 - 2024. All rights reserved.