【问题标题】:How can I pass the intercepted key through to an application in autohotkey如何将截获的密钥传递给 autohotkey 中的应用程序
【发布时间】:2011-01-21 22:10:47
【问题描述】:

我经常激活 Firefox,然后点击 Ctrl+L 来聚焦位置栏并进行搜索或输入 URL。

理想情况下,我可以在任何应用程序中点击Ctrl+L,Firefox 将被激活,位置栏聚焦并准备好输入。在步骤 AutoHotkey 脚本中。

我已经尝试过了,但它似乎不起作用。根据我的阅读,波浪号是“直通”:

^l::
IfWinExist ahk_class MozillaUIWindowClass
{
    WinActivate
    Send ~^l
}

【问题讨论】:

  • 在我发布相同的基本问题之前大约 30 秒才发现这个。谢谢!

标签: keyboard-shortcuts autohotkey ctrl


【解决方案1】:

我认为波浪号在这种情况下不适用,但是 Send 发送密钥的速度可能比窗口实际激活的速度快,所以这样的事情可能会更好:

SetKeyDelay, 10, 10 ; adds 10ms delay between and during keystrokes
IfWinExist, ahk_class MozillaUIWindowClass
{
   WinActivate,
   WinWaitActive, ; waits until window is active
   Send, ^l
}
return

【讨论】:

    【解决方案2】:

    我自己在AHK forum 上得到了这个问题的答案。
    它需要使用美元符号修饰符 ($)。

    $^l::
    IfWinExist ahk_class MozillaUIWindowClass
    {
        WinActivate
        Send ^l
    }  
    


    来自 AutoHotkey 帮助:

    ($) 这通常只有在脚本使用发送命令发送组成热键本身的键时才需要,否则可能会导致它自己触发。


    这是我最终使用的完整脚本。如果 Firefox 已经处于活动状态,则 Ctrl+L 会简单地通过并像往常一样运行。如果按下 Ctrl+L 时在 Firefox 之外,则激活 Firefox 并创建一个新选项卡;准备好搜索了。

    $^l::
    IfWinExist ahk_class MozillaUIWindowClass
    {
      IfWinActive ahk_class MozillaUIWindowClass
      {
        Send ^l
      }
      else
      {
        WinActivate
        Send ^t
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-27
      • 2020-10-26
      • 2021-11-15
      • 2019-11-21
      • 1970-01-01
      • 1970-01-01
      • 2017-12-16
      • 1970-01-01
      相关资源
      最近更新 更多