AutoIT 执行应用程序热键

AutoIT execute application hotkey

我看到有很多关于使用 autoit 设置热键的指南。不过我想做的是执行一个应用程序热键。

例如,我有这个来加载 firefox

Run(@ProgramFilesDir & "\Mozilla Firefox\firefox.exe", "", @SW_MINIMIZE)
Opt("WinTitleMatchMode", 2)
WinWait("Mozilla Firefox")
WinSetState("Mozilla Firefox", "", @SW_MINIMIZE)

现在在 firefox 的菜单中,我可以看到 Ctrl + D 的组合可以为页面添加书签。加载 firefox 后,有什么方法可以通过 autoit 执行此操作?

谢谢

只需使用发送命令。另请查看 SendKeepActive。

有几种方法可以做到这一点。我将在下面列出几种不同的方法。

方法一 - 发送密钥

; Below is simply the code you listed in the example to open Firefox and wait for it to load.
Run(@ProgramFilesDir & "\Mozilla Firefox\firefox.exe", "", @SW_MINIMIZE)
Opt("WinTitleMatchMode", 2)
WinWait("Mozilla Firefox")
WinSetState("Mozilla Firefox", "", @SW_MINIMIZE)

; Once FireFox is loaded, and you are at the page you want to bookmark, send Ctrl+D to the page to bookmark it. Since you started the browser Minimized, you will need to activate the page first.

; Activate the window
WinActivate("Mozilla Firefox")

; Send "Ctrl + D"
Send("^d")

方法二 - AutoIt 热键

; Create a HotKey controller
HotKeySet("^d", "bookmarkPage")

; Your code is below again.
Run(@ProgramFilesDir & "\Mozilla Firefox\firefox.exe", "", @SW_MINIMIZE)
Opt("WinTitleMatchMode", 2)
WinWait("Mozilla Firefox")
WinSetState("Mozilla Firefox", "", @SW_MINIMIZE)


; The function that is called when "Ctrl + D" is pressed.

Func bookmarkPage ()
    ; Activate the window
    WinActivate("Mozilla Firefox")

    ; Send they keys
    Send("^d")
EndFunc

方法三——MouseMove(不推荐)

; Your code below
Run(@ProgramFilesDir & "\Mozilla Firefox\firefox.exe", "", @SW_MINIMIZE)
Opt("WinTitleMatchMode", 2)
WinWait("Mozilla Firefox")
WinSetState("Mozilla Firefox", "", @SW_MINIMIZE)

; Use the mouse move function to move the cursor to the 'Bookmark' icon.
MouseMove(xxxx,xxxx)
Sleep(100)
MouseClick("left")

我强烈建议不要使用最后一个选项。我希望其中之一对你有用!

在 FireFox window 激活的情况下,只需使用“发送”命令。

Send("^d")