如何将截获的密钥传递给 autohotkey 中的应用程序

发布于 2024-08-23 01:26:03 字数 325 浏览 7 评论 0原文

我经常激活 Firefox,然后按 Ctrl+L 聚焦地址栏并进行搜索或输入 URL。

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

我已经尝试过这个,但似乎不起作用。根据我的阅读,波形符是“传递”:

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

I'm constantly activating Firefox then hitting Ctrl+L to focus the location bar and do a search or type a URL.

Ideally I can be in any application and hit Ctrl+L and Firefox will be activated with the location bar focused and ready for input. In steps AutoHotkey scripting.

I've tried this and it doesn't seem to work. From what I've read, tilde is "pass-through":

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你好,陌生人 2024-08-30 01:26:03

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

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

来自 AutoHotkey 帮助:

($) 通常仅当脚本使用 Send 命令发送包含热键本身的键时才需要这样做,否则可能会导致其自行触发。

这是我最终使用的完整脚本。如果 Firefox 已处于活动状态,则只需传递 Ctrl+L 即可正常运行。如果在 Firefox 外部,按下 Ctrl+L 则会激活 Firefox 并创建一个新选项卡;准备好进行搜索。

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

Ended up getting the answer to this one myself on the AHK forum.
It requires the use of the dollar sign modifier ($).

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

From AutoHotkey help:

($) This is usually only necessary if the script uses the Send command to send the keys that comprise the hotkey itself, which might otherwise cause it to trigger itself.

And here's the full script I ended up using. If Firefox is already active Ctrl+L is simply passed through and behaves as usual. If outside of Firefox when Ctrl+L is pressed then Firefox is activated and a new tab is created; ready for searching.

$^l::
IfWinExist ahk_class MozillaUIWindowClass
{
  IfWinActive ahk_class MozillaUIWindowClass
  {
    Send ^l
  }
  else
  {
    WinActivate
    Send ^t
  }
}
段念尘 2024-08-30 01:26:03

我不认为波浪号适用于这种情况,但 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

I don't think the tilde applies in this instance, but Send might send the keys faster than the window actually activates, so something like this might be better:

SetKeyDelay, 10, 10 ; adds 10ms delay between and during keystrokes
IfWinExist, ahk_class MozillaUIWindowClass
{
   WinActivate,
   WinWaitActive, ; waits until window is active
   Send, ^l
}
return
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文