AutoHotKey,将焦点放在按钮网页上并发送点击
AutoHotKey, set focus on a button webpage and send click
我的 html 页面上有一个按钮,标题为 window "Page":
<button onclick="alert('This button has been clicked')">Submit</button>
并使用 AutoHotKey,我试图将焦点设置在他身上,然后发送鼠标点击。
这是我写的AHK代码:
^p::
ControlFocus, Submit, Page
MouseClick left
return
按 Ctrl+P 键后,它应该可以完成他的工作。不幸的是,它不起作用。我已经阅读了包含一些示例的文档,但无法正常工作...
您可以在此处了解有关将 AHK 与 HTML DOM 集成的更多信息:
https://autohotkey.com/boards/viewtopic.php?f=7&t=4588
请参阅以下示例,了解如何实现此类目标。
示例
#SingleInstance, off
OnExit,OnExit
Gui Add, ActiveX, x0 y0 w640 h480 vWB, Shell.Explorer ; The final parameter is the name of the ActiveX component.
WB.silent := true ;Surpress JS Error boxes
WB.navigate("http://example.com/") ;put your web address here...
ComObjConnect(WB, WB_events) ; Connect WB's events to the WB_events class object.
Gui Show, w640 h480
return
GuiClose:
OnExit:
ExitApp
class WB_events
{
;NavigateComplete2(wb, NewURL)
;DownloadComplete(wb, NewURL)
DocumentComplete(wb, NewURL)
{
if (WB.ReadyState == 4) { ; see
Sleep, 300 ;wait 300 ms
;Do what you here...
;for example, click the first link on the page, you can change this for a button.
wb.document.getElementsByTagName("a")[0].click()
MsgBox Item was clicked.
}
return
}
}
我的 html 页面上有一个按钮,标题为 window "Page":
<button onclick="alert('This button has been clicked')">Submit</button>
并使用 AutoHotKey,我试图将焦点设置在他身上,然后发送鼠标点击。
这是我写的AHK代码:
^p::
ControlFocus, Submit, Page
MouseClick left
return
按 Ctrl+P 键后,它应该可以完成他的工作。不幸的是,它不起作用。我已经阅读了包含一些示例的文档,但无法正常工作...
您可以在此处了解有关将 AHK 与 HTML DOM 集成的更多信息:
https://autohotkey.com/boards/viewtopic.php?f=7&t=4588
请参阅以下示例,了解如何实现此类目标。
示例
#SingleInstance, off
OnExit,OnExit
Gui Add, ActiveX, x0 y0 w640 h480 vWB, Shell.Explorer ; The final parameter is the name of the ActiveX component.
WB.silent := true ;Surpress JS Error boxes
WB.navigate("http://example.com/") ;put your web address here...
ComObjConnect(WB, WB_events) ; Connect WB's events to the WB_events class object.
Gui Show, w640 h480
return
GuiClose:
OnExit:
ExitApp
class WB_events
{
;NavigateComplete2(wb, NewURL)
;DownloadComplete(wb, NewURL)
DocumentComplete(wb, NewURL)
{
if (WB.ReadyState == 4) { ; see
Sleep, 300 ;wait 300 ms
;Do what you here...
;for example, click the first link on the page, you can change this for a button.
wb.document.getElementsByTagName("a")[0].click()
MsgBox Item was clicked.
}
return
}
}