使用 AutoHotKey 查找并填充输入字段 [英] Find and fill an input field with AutoHotKey

查看:45
本文介绍了使用 AutoHotKey 查找并填充输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对所有 AutoHotKey 高手的挑战:

A challenge to all you AutoHotKey masters:

给我们一个函数,该函数将查找和移动光标到输入字段(例如登录名),或者发送输入文本.对于像我这样只是摆弄 AHK 的老而懒惰的黑客来说,它看起来像这样:

Give us a function that will Find and Move the Cursor to an Input Field (E.g. LoginName) and, alternatively send input text. For the old, lazy hackers like myself just fiddling with AHK, it would look like this:

FindFillField(*elementid*,*sendtext*,*alt-text*)

其中 elementid 是该字段的 HTML id,例如用户名,其中 sendtext 是要填充的文本其中 alt-text 可以是附加的特定文本,以帮助识别字段.

Where elementid is the HTML id for the field, e.g. USERNAME, where sendtext is the text to fill and where alt-text could be additional, specific text to help identify the fields.

额外的可选参数总是有助于解决奇怪的情况,所以让你的想象力疯狂吧!

Additional, optional parameters are always helpful to round out odd cases so let your imaginations run wild!

对于像我这样的老手和任何人来说,创建简单的登录宏将是一件幸事.

For old-timers like me, and for anyone, this would be a blessing in creating simple login macros.

推荐答案

您可以使用以下代码将文本发送到输入字段:

You can send text to an input field with the following code:

wb.document.getElementById("login-username").value := "myUserName"

其中wb是COM对象,login-username是输入字段的ID,myUserName是你想输入的.

Where wb is the COM object, login-username is the ID of the input field, and myUserName is what you wish to input.

插入ID,也可以通过名称getElementsByName(...)、标签名getElementsByTagName(...)或类名来查找输入字段>getElementsByClassName(...).我找到了 本教程 有用.使用 Chrome 或 Firefox 找出如何识别输入字段(右键单击并按检查元素").

Insted of ID, you can also find the input field by name getElementsByName(...), tag name getElementsByTagName(...) or class name getElementsByClassName(...). I've found this tutorial to be useful. Use Chrome or Firefox to find out how to identify the input field (rightclick and press "inspect element").

如果要将光标移动到输入字段,请使用

If you want to move the cursor to the input field, use

wb.document.getElementById("login-username").focus()

这是一个完整的示例,使用 IE 和 Stack Overflow 登录页面:

Here is a full example, using IE and the Stack Overflow login page:

; Create IE instance
wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := True
wb.Navigate("https://stackoverflow.com/users/login")
; Wait for page to load:
While wb.Busy or wb.ReadyState != 4
    Sleep, 100
; Press "Log in using Stack Exchange"
wb.document.getElementById("se-signup-legend").click()
While wb.Busy or wb.ReadyState != 4
    Sleep, 100
; EITHER focus on the input field:
wb.document.getElementsByName("email")[0].focus()
; OR send text directly to the field:
wb.document.getElementsByName("email")[0].value := "my@email.com"

这篇关于使用 AutoHotKey 查找并填充输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆