AutoHotKey,将焦点设置在按钮网页上并发送单击

时间:2016-07-28 11:25:54

标签: autohotkey

我的html页面上有一个按钮,窗口标题为" Page":

<button onclick="alert('This button has been clicked')">Submit</button>

并使用AutoHotKey,我试图将注意力集中在他身上然后发送鼠标点击。

这是我写的AHK代码:

^p::
ControlFocus, Submit, Page
MouseClick left
return

按Ctrl + P键,它应该完成他的工作。不幸的是,它不起作用。我已经通过一些示例阅读了文档,但我无法让它工作......

1 个答案:

答案 0 :(得分:1)

您可以在此处学习更多关于将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 http://stackoverflow.com/a/9835755/883015
            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
    }
}