AHK 可以通过多种方式与网页进行交互。一种快速而肮脏的方法是简单地让 AHK 告诉浏览器去做。
可以在地址栏中使用 Javascript 与页面进行交互,但它有一些技巧。下面脚本中的 cmets 应该可以解释这一切:
+space:: ; Triggered with Shift+Space
GoSub mySub1
Return
mySub1:
;The original clipboard contents is first saved in a variable so that it is not lost when the script is run.
originialClipboard := Clipboard
;The clipboard is used so that the text is quickly entered into the address bar, instead of having each character typed out.
;Javascript is used to simulate a click on the desired document element. The 'j' is omitted by design.
Clipboard := "avascript:document.evaluate(""//a[text()='Search by parcel number']"", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();"
;CTRL+L puts the text cursor in the address bar. Then the letter "j" is typed, because Chrome does not allow the text "javascript:" to be pasted in. The rest of that string will be pasted in later.
send ^lj ;
;CTRL+V pastes the clipbard
send ^v
sleep 1 ;Sleep for a short moment to allow the browser to catch up.
send {enter} ;The Enter key is sent, executing the javascript, simulating a click on the button.
;The clipboard is restored to its original value
clipboard := originialClipboard
Return