<p><strong><span>四、模拟键击和鼠标点击</span></strong></p><p><span>1</span><span>、模拟鼠标点击(按钮等)控件</span></p><p><span>既然是模拟用户操作,自然就包括了模拟鼠标点击在内。</span></p><p><span>适用命令</span><span>/</span><span>函数:</span><span>Click/<span>MouseClick/ControlClick</span></span></p><p><span>其中</span><span>Click/<span>MouseClick</span></span><span>用来模拟用户的物理操作(点击),把鼠标点击事件发送到指定坐标位置(相对当前窗口或绝对位置)上,但这种方法并不能保证</span><span>100%</span><span>的准确性,屏幕分辨率、用户干扰和系统环境等都会影响到它们的执行结果,而</span><span><span>ControlClick</span></span><span>则直接把鼠标点击事件发送到目标窗口的目标控件上,因而更准确,一般我们不考虑使用坐标位置方式的点击,下面仅以</span><span><span>ControlClick</span></span><span>为例说明:</span></p><p><span>AHK</span><span>:</span></p><p><span><span>ControlClick</span></span><span> [, </span><span>目标控件或坐标位置</span><span>, </span><span>窗口标题</span><span>, </span><span>窗口文本</span><span>, </span><span>鼠标按钮</span><span>, </span><span>点击次数</span><span>, </span><span>选项</span><span>,</span><span>排除标题</span><span>, </span><span>排除文本</span><span>]</span></p><p><span>AU3</span><span>:</span></p><p><span><span>ControlClick</span></span><span> ( "</span><span>窗口标题</span><span>", "</span><span>窗口文本</span><span>", </span><span>控件</span><span>ID [, </span><span>按钮</span><span>] [, </span><span>点击次数</span><span>]] )</span></p><p><span>对</span><span>AHK</span><span>而言,“目标控件”参数是指要点击的控件的类别名(</span><span><span>ClassNN</span></span><span>)或控件文本,另外还可以使用控件句柄(若用的是控件句柄则第一个参数需留空,并在第二个参数中使用</span><span><span>ahk_id</span></span><span> %</span><span>控件句柄</span><span>%</span><span>)。</span></p><p></p><p><span>Q</span><span>:用什么工具来获得目标控件的这些信息呢?</span></p><p><span>A</span><span>:</span><span>AHK</span><span>用户请使用</span><span> <span>AutoIt3 Window Spy</span></span><span>,</span><span>AU3</span><span>用户则请使用</span><span><span>AutoIt</span></span><span> Window Info</span><span>,你可以在相应的开始菜单项目里找到它们,或者到安装目录下寻找。</span></p><p></p><p><span>Q</span><span>:如何使用这两个工具?</span></p><p><span>A</span><span>:先打开你要进行操作的目标窗口,然后运行</span><span> <span>AutoIt3 Window Spy </span></span><span>或</span><span> <span><span>AutoIt</span></span><span> Window Info</span></span><span>,接下来就是把鼠标移到目标控件上(比如某个按钮):</span></p><div><span>AutoIt3 Window Spy </span><span>使用演示截图:</span> |