<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>SetCapsLockState / SetNumLockState / SetScrollLockState</h1> <p>设置 <kbd>CapsLock</kbd>/<kbd>NumLock</kbd>/<kbd>ScrollLock</kbd> 键的状态. 还可以强制这些键保持打开或关闭状态.</p> <pre class="Syntax"><span class="func">SetCapsLockState</span> <span class="optional">State</span> <span class="func">SetNumLockState</span> <span class="optional">State</span> <span class="func">SetScrollLockState</span> <span class="optional">State</span></pre> <h2 id="Parameters">参数</h2> <dl> <dt>State</dt> <dd> <p>类型: <a href="../Concepts.htm#strings">字符串</a>或<a href="../Concepts.htm#boolean">整数(布尔值)</a></p> <p>如果省略此参数, 则清除按键的 AlwaysOn/Off(如果存在) 状态. 否则, 请指定下列单词的其中一个:</p> <p><strong>On</strong> 或 1(<a href="../Variables.htm#True">true</a>): 打开按键并清除按键的 AlwaysOn/Off(如果存在) 状态.</p> <p><strong>Off</strong> 或 0(<a href="../Variables.htm#False">false</a>): 关闭按键并清除按键的 AlwaysOn/Off(如果存在) 状态.</p> <p><strong>AlwaysOn</strong>: 强制按键保持打开状态.</p> <p><strong>AlwaysOff</strong>: 强制按键保持关闭状态.</p> </dd> </dl> <h2 id="Remarks">备注</h2> <p>与下面的<a href="#ExToggle">示例 #2</a> 相比, 还可以通过 <a href="Send.htm">Send</a> 函数将按键切换到相反的状态; 例如: <code>Send "{CapsLock}"</code>. 但是, 发送 {CapsLock} 可能需要事先 <code><a href="SetStoreCapsLockMode.htm">SetStoreCapsLockMode</a> False</code>.</p> <p>保持一个按键 <em>AlwaysOn</em> 或 <em>AlwaysOff</em> 需要<a href="InstallKeybdHook.htm">键盘钩子</a>, 在这样的情况中会自动进行安装..</p> <h2 id="Related">相关</h2> <p><a href="SetStoreCapsLockMode.htm">SetStoreCapsLockMode</a>, <a href="GetKeyState.htm">GetKeyState</a></p> <h2 id="Examples">示例</h2> <div class="ex" id="ExBasic"> <p><a class="ex_number" href="#ExBasic"></a> 开启 <kbd>NumLock</kbd> 并移除键的 AlwaysOn/Off 属性(如果存在).</p> <pre>SetNumLockState True</pre> </div> <div class="ex" id="ExAlwaysOff"> <p><a class="ex_number" href="#ExAlwaysOff"></a> 强制 <kbd>ScrollLock</kbd> 永久关闭.</p> <pre>SetScrollLockState "AlwaysOff"</pre> </div> <div class="ex" id="ExToggle"> <p><a class="ex_number" href="#ExToggle"></a> 切换 <kbd>CapsLock</kbd> 到相反的状态.</p> <pre>SetCapsLockState !GetKeyState("CapsLock", "T")</pre> </div> <a href="https://dftg.net">dftg</a><!-- Cloudflare Pages Analytics --><script defer src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon='{"token": "d5a9c4fcb9b6482fa53ce820d892f969"}'></script><!-- Cloudflare Pages Analytics --><script defer src="https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon='{"rayId":"92b8112b6c2f0280","version":"2025.3.0","r":1,"serverTiming":{"name":{"cfExtPri":true,"cfL4":true,"cfSpeedBrain":true,"cfCacheStatus":true}},"token":"51750bb5dc4f40cc91a5ec55c63bbc01","b":1}' crossorigin="anonymous"></script> </body> </html>