【问题标题】:AutoHotKey - Send singular key press on program launchAutoHotKey - 在程序启动时发送单数按键
【发布时间】:2020-01-17 12:34:04
【问题描述】:

我希望在程序打开后立即按下 F11 键,而无需按下任何热键等,基本上是在启动时自动按下按键。这是我的代码:

; This section fullscreens XENIA on Play
#SingleInstance, Force

numpad0::
IfWinExist, ahk_class XeniaWindowClass ahk_exe xenia.exe
{
    WinActivate, ahk_class XeniaWindowClass
    #IfWinActive, ahk_class XeniaWindowClass
    {
        Send, {F11}
    }
}
return

如有任何帮助,谢谢!

【问题讨论】:

  • 您能否详细说明您的代码“不起作用”的原因?你期待什么,实际发生了什么?请edit这些详细信息,否则我们可能无法提供帮助。
  • 查看我对您之前帖子的回答。
  • 当然,因为我的程序默认情况下以窗口形式启动并且它被锁定,所以我希望我的代码在启动并检测到程序后立即将 F11(它全屏显示程序)发送到程序,以便它全屏显示.正如您现在在我的代码中看到的那样,我已经包含了 numpad0:: 来测试我的代码是否确实如此,但我不想按任何键,我希望在启动时自动为我完成所有这些操作。

标签: autohotkey


【解决方案1】:

哦,我明白了。那么这就是你的做法。您运行该函数,也可以通过按numpad0 调用它(但是,您必须在运行程序后启动此脚本,或查看我在上一篇文章中的回答):

; This section fullscreens XENIA on Play
#Persistent
#SingleInstance, Force

GoSub, DoIt
return

numpad0::
GoSub, DoIt
return

DoIt:
IfWinExist, ahk_class XeniaWindowClass ahk_exe xenia.exe
{
    WinActivate, ahk_class XeniaWindowClass
    #IfWinActive, ahk_class XeniaWindowClass
    {
        Send, {F11}
    }
}
return

Hth,lmk。 . .

【讨论】:

  • @IanB 我还在你的其他帖子中详细说明了答案。
【解决方案2】:

可能是这样的?

#Persistent
SetTimer, XeniaWatcher

XeniaWatcher() {
    WinWaitActive, ahk_class XeniaWindowClass
    Send, {F11}
    WinWaitNotActive, ahk_class XeniaWindowClass
}

还是这个?

#Persistent
SetTimer, XeniaWatcher

XeniaWatcher() {
    WinWaitActive, ahk_class XeniaWindowClass
    Send, {F11}
    WinWaitClose, ahk_class XeniaWindowClass
}

【讨论】:

  • 你的 AHK 好像已经过时了。
【解决方案3】:
; This section fullscreens XENIA on Play
#SingleInstance, Force
SetInterval, check, 200 ; check every 200ms
sentB4:=0

check:
If ( (WinExist("ahk_class XeniaWindowClass")) && (WinExist("ahk_exe xenia.exe")) ) {
    If (sentB4 == 0) {
        WinActivate, ahk_class XeniaWindowClass
        If ( WinActive("ahk_class XeniaWindowClass") ) {
            send, {F11} ; send desired key (fullscreen in this case)
            sentB4:=1 ; update status
        }
    }
} else {
    sentB4:=0 ; reset status
}
return

我更新了您过时的 IfWinExist 函数,因为它们已被弃用,请阅读 cmets 了解更多信息

numpad0::
    gosub, check
    return

也添加手动触发...

【讨论】:

    猜你喜欢
    • 2018-07-02
    • 2012-03-15
    • 1970-01-01
    • 1970-01-01
    • 2016-12-01
    • 2016-04-18
    • 1970-01-01
    • 2022-10-09
    • 1970-01-01
    相关资源
    最近更新 更多