I think SendInput is pretty fast.
Code: Select all
F2::
Send {F6}
SendInput {Text}javascript:void(document.getElementById("header-search-bar").value="Hello world 1")
Send {Enter}
return
The following code uses
Acc.ahk, it works even when Chrome window is inactive.
Code: Select all
js := "void(document.getElementById('header-search-bar').value='Hello world 1')"
ChromeRunJs(js)
ChromeRunJs(ByRef js) {
static addrBar
if !addrBar || !WinExist("ahk_id " addrBar.hWnd) {
if !addrBar := FindAddressBar() {
throw "FindAddressBar failed."
}
}
addrBar.accObj.accValue(0) := "javascript" . Chr(58) . js
addrBar.accObj.accSelect(0x1, 0)
ControlSend,, {Enter}
}
FindAddressBar(WinTitle := "ahk_exe chrome.exe", oAcc := "", accPath := "") {
if !oAcc {
if hWnd := WinExist(WinTitle) {
oAcc := Acc_ObjectFromWindow(hWnd)
while oAcc.accRole(0) != 9 { ; ROLE_SYSTEM_WINDOW := 9
oAcc := Acc_Parent(oAcc)
}
} else {
throw WinTitle " not found."
}
}
for i, child in Acc_Children(oAcc) {
nRole := child.accRole(0)
if (nRole = 42) { ; ROLE_SYSTEM_TEXT := 42
if (child.accName(0) ~= "i)address|地址") {
accPath := LTrim(accPath "." i, ".")
return {accObj: child, accPath: accPath, hWnd: hWnd}
}
}
/*
ROLE_SYSTEM_APPLICATION := 14
ROLE_SYSTEM_PANE := 16
ROLE_SYSTEM_GROUPING := 20
ROLE_SYSTEM_TOOLBAR := 22
ROLE_SYSTEM_COMBOBOX := 46
*/
static oGroup := {14:1, 16:1, 20:1, 22:1, 46:1}
if oGroup.HasKey(nRole) {
if result := FindAddressBar(, child, accPath "." i) {
return result
}
}
}
}
The forum does not allow the string:
- javascript.png (862 Bytes) Viewed 4600 times
to appear in the posts, so I used
"javascript" . Chr(58) instead.