有没有办法在自动热键中编写自动热键?例如,我有一个自动热键,可以在我工作的选项卡中打开一些网站,并且我有一个自动热键,当我输入其中一些网站的用户名和密码时。有没有办法将密码自动热键 (actd(at symbol)) 放入 IE 选项卡自动热键中?我进行了一些搜索,但似乎无法发送 {@},所以我不确定是否有其他方法可以发送。
4 回答
您可以做的是编写两个单独的脚本。一个没有分配自动热键,但被初始脚本调用。在您的情况下,您已经说过您已经有一个 tabopening 热键,所以我将使用两个脚本的一个非常基本的示例,但演示如何发送 @ 符号并从热键中调用另一个脚本。
我将使用的两个脚本是:
tabOpener.ahk
和
passwordEntry.ahk
它们将如下所示:
tabOpener.ahk
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; hotkey is set as WinowsKey+t and checks if FireFox exists, if so, it makes it active, if not, it starts FireFox
~#t::
IfWinExist, ahk_class MozillaWindowClass
{ WinActivate
Send ^t
} else run firefox
;Upon opening a new tab in FireFox, the address bar has already got focus,
;so send the web address (You can use COM functions for this, and are highly
;recommended, but out of the scope of this example)
Send, hotmail.com{Enter}
;Waits until page is loaded. Again COM functions are available as they can tell
;when a page is finished loading, but that is a more involved example.
Sleep 5000
;Calls the password entry script.
Run passwordEntry.ahk
return
密码输入.ahk
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;When using send, adding the {Raw} tag will literally interpret every
;character in the remainder of a string. For instance ^ will send ^
;instead of a Control keypress.
Send {Raw}Username@domain.tld
Send {Tab} {Raw}Password
希望这会有所帮助。这个例子展示了使用 {Raw} 标记来发送特殊字符 ( http://www.autohotkey.com/docs/commands/Send.htm ),此外还使用 Run / 从现有热键中调用单独的脚本运行等待(http://www.autohotkey.com/docs/commands/Run.htm)。
;~ Alt+1 to send username (email format) and password
!1::Send, myUsername@mydomain.com{tab}myPassword{enter}
根据您的网络浏览器,您可以使用 COM 对象非常轻松地处理此问题。您会找到用户 ID 密码字段,然后例如:
url := "http://yourwebsite.com"
wb := ComObjCreate("InternetExplorer.Application") ; create broswer object
wb.navigate(url)
wb.visible := true ; sets the browser as visible, defaults as not
While (wb.busy || wb.readyState <> 4)
Sleep 100<br>
wb.document.all.username.value := "yourname@wherever.com"
wb.document.all.password.value := "Pa$$word15"
wb.document.all.btnLogin.click()
然而,这取决于您是否使用 IE 访问您的网站。稍微看一下文档中的 COM 对象以了解它,您将了解一些关于 DOM 的非常基本的东西,这里是:Basic DOM MSDN。我在 javascript 中设置“用户名”、“密码”和“btnLogin”控件 ID 的位置需要通过查看您的页面来发现。您还应该查看本教程:AHK Basic COM/JavaScript Tutorial