11

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

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

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

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

2 回答 2

20

最终我自己在AHK 论坛上得到了这个答案。
它需要使用美元符号修饰符 ($)。

$^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
  }
}
于 2010-03-01T16:37:00.383 回答
0

我认为波浪号在这种情况下不适用,但是 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
于 2010-03-01T02:47:34.313 回答