How to change caps lock status without key press

余生颓废 提交于 2019-11-30 12:38:01
Daniel Vassallo

On Linux:

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)

Source: Benji York - Stack Overflow: Change keyboard locks in Python


On Windows:

You should be able to use SendKeys for this, as in the following example:

import SendKeys

SendKeys.SendKeys("""
{CAPSLOCK}
""")
Adam Matan

Use sendkeys to change the status and keyboardleds to change the LED indicators.

sendkeys:

From another SO dicussion:

import SendKeys

SendKeys.SendKeys("""
{CAPSLOCK}
{SCROLLOCK}
{NUMLOCK}
""")

keyboardleds:

This package seems to work only for POSIX (which is OK if you're using Ubuntu), and you can read more here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!