Send 和 ControlSend 有什么区别?

What's the difference between Send and ControlSend?

AutoHotkey 的官方文档列出了两组不同的命令,用于将模拟键盘输入发送到 window。

Send / SendRaw / SendInput / SendPlay / SendEvent

Sends simulated keystrokes and mouse clicks to the active window.

ControlSend / ControlSendRaw

Sends simulated keystrokes to a window or control.


Send/SendXXX 命令将输入​​发送到 活动 window。那就是当前拥有 焦点 的 window,通常是通过用鼠标单击它、跳转到它,或者当 window 将焦点设置到它自己时。

如果您的 AHK 脚本以您打开的记事本 window 为目标,并且您要单击另一个 window,例如 Chrome,您的输入现在将被发送至 Chrome.

另一方面,使用 ControlSend/ControlSendXXX 命令会将输入发送到指定的 windowcontrol。控件可以是文本框、按钮或类似的交互元素。

此处,即使您将焦点切换到另一个 window,例如 Chrome,上述示例仍会输出到记事本。缺点是必须指定发送到哪个控件。