擅长:python、mysql、java
<p><strong>在Linux上:</strong></p>
<pre><code>import fcntl
import os
KDSETLED = 0x4B32
console_fd = os.open('/dev/console', os.O_NOCTTY)
# Turn on caps lock
fcntl.ioctl(console_fd, KDSETLED, 0x04)
# Turn off caps lock
fcntl.ioctl(console_fd, KDSETLED, 0)
</code></pre>
<p>来源:<a href="https://stackoverflow.com/questions/854393/change-keyboard-locks-in-python/858992#858992">Benji York - Stack Overflow: Change keyboard locks in Python</a></p>
<hr/>
<p><strong>在Windows上:</strong></p>
<p>您应该能够为此使用<a href="http://www.rutherfurd.net/python/sendkeys/" rel="nofollow noreferrer">SendKeys</a>,如下例所示:</p>
<pre><code>import SendKeys
SendKeys.SendKeys("""
{CAPSLOCK}
""")
</code></pre>