<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1632085368384154" crossorigin="anonymous"></script><script src="https://autohotkey.top/gtag.js"></script></head> <body><h1>AutoHotkey_L 新特性</h1> <p>这个页面描述了新添加到 AutoHotkey_L 分支的功能, 现在简称为 "AutoHotkey 1.1".</p> <p class="warning"><strong>警告:</strong> 近年来本文档已被忽视, 可能会丢失一些最近的变化.</p> <h2 id="flow">流程控制</h2> <table class="info"> <tr> <th>特性</th> <th abbr="Descr">描述</th> </tr> <tr><td width="20%"><a href="commands/Break.htm">Break <i>LoopLabel</i></a></td><td width="80%">退出一个循环或任意数目的嵌套循环.</td></tr> <tr><td><a href="commands/Continue.htm">Continue <i>LoopLabel</i></a></td><td>继续循环, 即使在任意数目的嵌套循环中.</td></tr> <tr><td><a href="commands/For.htm">For <i>x</i>,<i>y</i> in <i>z</i></a></td><td>从头到为尾循环对象的内容.</td></tr> <tr><td><a href="commands/Until.htm">Loop Until</a></td><td>循环直到条件为真. 可用于任意类型的循环.</td></tr> <tr><td><a href="commands/Try.htm">Try</a>...<a href="commands/Catch.htm">Catch</a>...<a href="commands/Finally.htm">Finally</a></td><td>提供结构化的异常处理机制.</td></tr> <tr><td><a href="commands/Throw.htm">Throw</a></td><td>抛出异常.</td></tr> </table> <h2 id="commands">命令</h2> <table class="info"> <tr> <th>特性</th> <th abbr="Descr">描述</th> </tr> <tr><td width="20%"><a href="commands/FileEncoding.htm">FileEncoding</a></td><td width="80%">为 <a href="commands/FileRead.htm">FileRead</a>, <a href="commands/FileReadLine.htm">FileReadLine</a>, <a href="commands/LoopReadFile.htm">Loop Read</a>, <a href="commands/FileAppend.htm">FileAppend</a> 和 <a href="commands/FileOpen.htm">FileOpen()</a> 设置默认编码.<br><i>另请参阅:</i> <a href="#enc">文本编码</a></td></tr> <tr><td><a href="commands/Gui.htm">Gui</a></td><td>请参阅后面的 <a href="#GUI_Enhancements">GUI 增强</a>.</td></tr> <tr><td><a href="commands/IniRead.htm">IniRead</a>/<a href="commands/IniWrite.htm">Write</a>/<a href="commands/IniDelete.htm">Delete</a></td><td>读取, 写入或删除整段, 或获取所有段名称组成的列表.</td></tr> <tr><td><a href="commands/Menu.htm#MenuIcon">Menu, Icon</a></td><td>设置或移除菜单项图标.</td></tr> <tr><td><a href="commands/Run.htm">Run</a></td><td><a href="Compat.htm#Run">改进</a>了参数的解析方式.</td></tr> <tr><td><a href="commands/Send.htm#Unicode">SendInput {U+nnnn}</a></td><td>发送 Unicode 字符. 在 Unicode 版本中可以直接使用 Unicode 字符.</td></tr> <tr><td><a href="commands/SendLevel.htm">SendLevel</a></td><td>控制热键和热字串是否忽略模拟的键盘和鼠标事件.</td></tr> <tr><td><a href="commands/SetFormat.htm">SetFormat, IntegerFast, h|H</a></td><td>设置小写或大写的十六进制格式.</td></tr> <tr><td><a href="commands/SetRegView.htm">SetRegView, RegView</a></td><td>允许 32 位脚本中的注册表命令访问 64 位注册表视图, 反之亦然.</td></tr> <tr><td><a href="commands/Transform.htm#HTML">Transform, HTML</a></td><td>执行代码页或 HTML 转换.</td></tr> <tr><td><a href="commands/WinGet.htm#ProcessPath">WinGet, ..., ProcessPath</a></td><td>获取拥有指定窗口的进程的完整路径和名称.</td></tr> </table> <h2 id="directives">指令</h2> <table class="info"> <tr> <th>特性</th> <th abbr="Descr">描述</th> </tr> <tr><td width="20%"><a href="commands/_If.htm">#If <i>expression</i></a></td><td width="80%">类似于 <a href="commands/_IfWinActive.htm">#IfWinActive</a>, 但可以是任意类型的表达式.</td></tr> <tr><td><a href="commands/_IfTimeout.htm">#IfTimeout</a></td><td>设置计算单个 #If 表达式可以使用的最大时间.</td></tr> <tr><td><a href="commands/_MenuMaskKey.htm">#MenuMaskKey</a></td><td>改变用来屏蔽 Win 或 Alt 键松开事件的按键.</td></tr> <tr><td><a href="commands/_Include.htm">#Include &lt;Lib&gt;</a></td><td>包含函数库文件夹中的脚本文件.</td></tr> <tr><td><a href="commands/_InputLevel.htm">#InputLevel</a></td><td>控制热键和热字串是否忽略模拟的键盘和鼠标事件.</td></tr> <tr><td><a href="commands/_Warn.htm">#Warn</a></td><td>启用或禁用为选择的情况提示开发者错误的警告.</td></tr> </table> <h2 id="functions">函数</h2> <table class="info"> <tr> <th>特性</th> <th abbr="Descr">描述</th> </tr> <tr><td width="20%"><a href="commands/ComObjActive.htm">ComObj...</a> --<br>ComObjActive<br>ComObjEnwrap/Unwrap<br>ComObjParameter<br>ComObjType</td><td width="80%"><br>获取一个注册的 COM 对象.<br>包装/解开 COM 对象.<br>把值和类型包装成参数传递.<br>获取 COM 对象的类型信息.</td></tr> <tr><td><a href="commands/ComObjArray.htm">ComObjArray</a></td><td>创建用于 COM 的 SAFEARRAY.</td></tr> <tr><td><a href="commands/ComObjConnect.htm">ComObjConnect</a></td><td>连接 COM 对象的事件源到带有给定前缀的函数.</td></tr> <tr><td><a href="commands/ComObjCreate.htm">ComObjCreate</a></td><td>创建 COM 对象.</td></tr> <tr><td><a href="commands/ComObjError.htm">ComObjError</a></td><td>启用或禁用 COM 错误通告.</td></tr> <tr><td><a href="commands/ComObjFlags.htm">ComObjFlags</a></td><td>获取或改变控制 COM 包装器对象行为的标志.</td></tr> <tr><td><a href="commands/ComObjGet.htm">ComObjGet</a></td><td>返回由 COM 组件提供的对象引用.</td></tr> <tr><td><a href="commands/ComObjQuery.htm">ComObjQuery</a></td><td>查询 COM 对象的接口或服务.</td></tr> <tr><td><a href="commands/ComObjType.htm">ComObjType</a></td><td>从 COM 对象获取类型信息.</td></tr> <tr><td><a href="commands/ComObjValue.htm">ComObjValue</a></td><td>获取存储在 COM 包装器对象中的值或指针.</td></tr> <tr><td><a href="commands/Throw.htm#Exception">Exception</a></td><td>创建用于 <a href="commands/Throw.htm">Throw</a> 的异常对象(同时提供对堆栈的受限访问).</td></tr> <tr><td><a href="commands/FileOpen.htm">FileOpen</a></td><td>提供面向对象的文件 I/O.</td></tr> <tr><td><a href="commands/Func.htm">Func</a></td><td>获取函数的<a href="Objects.htm#Function_References">引用</a>.</td></tr> <tr><td><a href="commands/GetKey.htm">GetKeyName/VK/SC</a></td><td>获取按键的名称, 文本, 虚拟按键码或扫描码.</td></tr> <tr><td><a href="commands/InStr.htm">InStr</a></td><td>搜索字符串的 <em>出现位置</em>, 从左边或右边开始.</td></tr> <tr><td><a href="commands/IsByRef.htm">IsByRef</a></td><td>判断变量是否是 ByRef 参数.</td></tr> <tr><td><a href="Objects.htm">IsObject</a></td><td>判断某个值是否为对象.</td></tr> <tr><td><a href="commands/StrPut.htm">StrPut</a> / <a href="commands/StrGet.htm">StrGet</a></td><td>复制字符串到内存地址或来自内存地址, 并可选地对其在不同代码页间进行转换.</td></tr> <tr><td><a href="commands/Trim.htm">Trim</a></td><td>移除字符串的开始和/或末尾的某些字符.</td></tr> <tr><td><a href="misc/RegExCallout.htm">RegEx (?C<i>Num</i>:<i>Func</i>)</a></td><td>在正则表达式进行模式匹配期间调用函数.</td></tr> <tr><td><a href="#Function_Libraries">函数库</a></td><td>新的 "本地库" 和 <code>#Include &lt;LibName&gt;</code>.</td></tr> <tr><td><a href="Functions.htm#Variadic">可变参数函数</a></td><td>函数可以通过数组接受可变数目的参数.</td></tr> <tr><td><a href="#Static">静态初始化</a></td><td>静态变量现在可以使用任意表达式进行初始化.</td></tr> </table> <h2 id="objects">对象</h2> <table class="info"> <tr> <th>特性</th> <th abbr="Descr">描述</th> </tr> <tr><td width="20%"><a href="Objects.htm">概述</a></td><td width="80%">对象的常规行为和用法.</td></tr> <tr><td><a href="Objects.htm#Arrays">对象</a></td><td>可以使用其他功能扩展的关联数组.</td></tr> <tr><td><a href="objects/Enumerator.htm">枚举器</a></td><td>可以枚举容器中的项目.</td></tr> <tr><td><a href="objects/File.htm">文件</a></td><td>提供访问文件的接口. <a href="commands/FileOpen.htm">FileOpen()</a> 返回文件类型的对象.</td></tr> <tr><td><a href="objects/Func.htm">Func</a></td><td>表示可以被脚本调用的自定义或内置的函数.</td></tr> <tr><td>ComObject</td><td>请参阅上面的 ComObj 函数.</td></tr> </table> <h2 id="vars">变量</h2> <table class="info"> <tr> <th>特性</th> <th abbr="Descr">描述</th> </tr> <tr><td width="20%">A_Is64bitOS</td><td width="80%">当操作系统为 64 位则值为 1(真), 为 32 位则为 0(假).</td></tr> <tr><td>A_IsUnicode</td><td>在 Unicode 版本中, 此变量值为 1(<i>true</i>). 在 ANSI 版本中此变量未定义, 所以等同为 <i>false</i>.</td></tr> <tr><td>A_FileEncoding</td><td>包含用于多种命令的默认编码, 请参阅 <a href="commands/FileEncoding.htm">FileEncoding</a>.</td></tr> <tr><td>A_OSVersion</td><td>支持 Windows 7 和 Windows 8, 请参阅 <a href="Variables.htm#OSVersion">A_OSVersion</a>.</td></tr> <tr><td>A_PriorKey</td><td>在最近按键按下或释放前最后按下的按键名称 ... <a href="Variables.htm#PriorKey">(更多细节)</a></td></tr> <tr><td>A_PtrSize</td><td>包含指针的大小, 单位为字节. 此大小为 4(32 位) 或 8(64 位).</td></tr> <tr><td>A_RegView</td><td>由 <a href="commands/SetRegView.htm">SetRegView</a> 设置的当前注册表视图.</td></tr> <tr><td>A_ScriptHwnd</td><td>脚本隐藏主窗口的唯一 ID(HWND/句柄).</td></tr> </table> <h2 id="types">数据类型</h2> <table class="info"> <tr> <th>特性</th> <th abbr="Descr">描述</th> </tr> <tr><td width="20%"><a href="commands/DllCall.htm#ptr">Ptr</a></td><td width="80%">在 32 位版本中等同于 <i>Int</i> 而在 64 位版本中为 <i>Int64</i>. 由 <a href="commands/DllCall.htm">DllCall()</a>, <a href="commands/NumPut.htm">NumPut()</a> 和 <a href="commands/NumGet.htm">NumGet()</a> 所支持.</td></tr> <tr><td><a href="commands/DllCall.htm#astr">AStr</a>, <a href="commands/DllCall.htm#wstr">WStr</a></td><td>仅 <a href="commands/DllCall.htm">DllCall()</a> 支持, 请参阅<a href="Compat.htm">脚本兼容性</a>.</td></tr> </table> <h2 id="unicode">Unicode</h2> <table class="info"> <tr> <th>特性</th> <th abbr="Descr">描述</th> </tr> <tr><td width="20%"><a href="Compat.htm">兼容性</a></td><td width="80%">在 DllCall() 中如何处理 Unicode 等.</td></tr> <tr><td><a href="Scripts.htm#cp">脚本文件</a></td><td>在脚本文件中使用 Unicode 编码.</td></tr> <tr><td><a href="commands/Send.htm#Unicode">SendInput</a></td><td>在 SendInput 中使用 Unicode.</td></tr> </table> <h2 id="other">其他</h2> <table class="info"> <tr> <th>特性</th> <th abbr="Descr">描述</th> </tr> <tr><td width="20%"><a href="misc/WinTitle.htm#ahk_exe">ahk_exe</a></td><td width="80%">窗口可以通过拥有此窗口的进程名称或路径(EXE 文件) 进行标识.</td></tr> <tr><td><a href="Scripts.htm#idebug">调试</a></td><td>交互式调试功能(单步执行等).</td></tr> <tr><td><a href="#Error_Handling">错误处理</a></td><td>Try/catch/throw 和增加的 A_LastError 可用性.</td></tr> <tr><td><a href="#GUI_Enhancements">GUI 增强</a></td><td>对 Gui 命令和相关部分的多方面增强.</td></tr> <tr><td><a href="#icons">图标支持</a></td><td>资源标识符和改进的对各种图标大小的支持.</td></tr> <tr><td><a href="Compat.htm">其他变更</a></td><td>影响脚本兼容性的改变.</td></tr> <tr><td><a href="AHKL_ChangeLog.htm">版本历史</a></td><td>AutoHotkey_L 的修订历史.</td></tr> </table> <h2 id="Error_Handling">错误处理</h2> <p>许多命令支持使用 <a href="commands/Try.htm">try</a>/<a href="commands/Catch.htm">catch</a> 代替 ErrorLevel 进行错误处理. 例如:</p> <pre class="NoIndent">try { FileCopy, file1.txt, C:\folder FileDelete, C:\folder\old.txt } catch MsgBox An error occured!</pre> <p>此外, 后面的这些命令现在设置 <a href="Variables.htm#LastError">A_LastError</a> 来辅助调试: FileAppend, FileRead, FileReadLine, FileDelete, FileCopy, FileMove, FileGetAttrib/Time/Size/Version, FileSetAttrib/Time, FileCreateDir, RegRead, RegWrite, RegDelete.</p> <h2 id="Function_Libraries">函数库</h2> <p>除了 <code>%A_MyDocuments%\AutoHotkey\Lib</code> 的用户库和在 AutoHotkey 目录的标准库外, 函数还可以从 <code>%A_ScriptDir%\Lib</code> 中的 "本地库" 自动加载. 想了解更多信息, 请参阅<a href="Functions.htm#lib">函数库</a>.</p> <p><a href="commands/_Include.htm">#Include &lt;LibName&gt;</a> 可以明确加载函数库中任意一个库文件.</p> <h2 id="GUI_Enhancements">GUI 增强</h2> <p>对 <a href="commands/Gui.htm">Gui</a> 命令和相关部分进行了一些增强:</p> <ul> <li>引用 GUI 时可以用<a href="commands/Gui.htm#MultiWin">名称或 HWND</a> 代替介于 1 和 99 之间的数字.</li> <li><a href="commands/Gui.htm#New">Gui, New</a> 创建新的匿名 GUI.</li> <li>可以创建任意数目的命名或匿名 GUI.</li> <li>新 GUI 选项: <a href="commands/Gui.htm#GuiHwndOutputVar">+Hwnd<em>OutputVar</em></a>, <a href="commands/Gui.htm#Parent">+Parent<em>GUI</em></a></li> <li>GUI 的拥有者可以为任意窗口: <a href="commands/Gui.htm#Owner">+Owner<em>%HWND%</em></a>.</li> <li><a href="commands/Gui.htm#fontq">Gui, Font</a> 可以控制文本的反锯齿效果.</li> <li>支持像 Internet Explorer WebBrowser 这样的 <a href="commands/GuiControls.htm#ActiveX">ActiveX 控件</a>.</li> <li><a href="commands/GuiControlGet.htm#Name">GuiControlGet, <em>OutputVar</em>, Name</a> 获取与 GUI 控件关联的变量名.</li> <li>在 <a href="commands/Gui.htm#Menu">Gui menus</a> 中使用像 <kbd>Ctrl</kbd>+<kbd>O</kbd> 这样的键盘快捷键时会自动得到支持.</li> <li><a href="commands/Gui.htm#fontq">字体品质</a>可以通过 Font 子命令控制.</li> </ul> <h2 id="Static">静态变量</h2> <p>静态变量现在可以使用任意表达式进行初始化. 例如:</p> <pre>Sleep 500 MsgBox % Time() "ms since the script started." Time() { static Tick := A_TickCount return A_TickCount - Tick }</pre> <h2 id="enc">文本编码</h2> <p><a href="commands/FileRead.htm">FileRead</a>, <a href="commands/FileReadLine.htm">FileReadLine</a>, <a href="commands/LoopReadFile.htm">Loop Read</a> 和 <a href="commands/FileAppend.htm">FileAppend</a> 支持 Windows 所支持的大部分文本编码, 而不限于系统默认的 ANSI 代码页. 可以用 <a href="commands/FileEncoding.htm">FileEncoding</a> 设置默认编码, 此设置在 FileRead 和 FileAppend 中可以使用如下方法覆盖:</p> <pre class="Syntax"> <span class="func">FileRead</span>, OutputVar, *P<i>nnn</i> Filename <span class="func">FileAppend</span> <span class="optional">, Text, Filename, Encoding</span> </pre> <p>此处 <i>nnn</i> 必须是数值的<a href="http://msdn.microsoft.com/en-us/library/dd317756.aspx">代码页标识符</a>, 而 <i>Encoding</i> 遵循与 <a href="commands/FileEncoding.htm">FileEncoding</a> 相同的格式.</p> <p><b>另请参阅:</b> <a href="Compat.htm#FileRead">脚本兼容性</a></p> <h2 id="Variadic">可变参数函数和函数调用</h2> <p><a href="Functions.htm#Variadic">可变参数函数</a>可以通过数组接受可变数目的参数, 而<a href="Functions.htm#VariadicCall">可变参数的函数调用</a>可以用来传递可变数目的参数给函数.</p> <h2 id="icons">图标支持的改进</h2> <h3 id="Unusual_Sizes">不常见的大小</h3> <p>可以从可执行文件中提取操作系统支持的任意大小的图标资源. 当图标组中存在多种大小的图标资源时, 则使用其中最合适的大小. 在修订号 17 之前的版本中, 系统先选择任意的图标资源, 接着调整到系统的大图标尺寸, 然后调整回请求的尺寸.</p> <h3 id="Resource_Identifiers">资源标识符</h3> <p>使用负数的图标编号可以标识可执行文件中的一组图标资源. 例如, 下面的语句设置托盘图标为 ahk 文件的默认图标.</p> <pre>Menu, Tray, Icon, %A_AhkPath%, -160</pre> <a href="https://dftg.net">dftg</a></body> </html>