How to change caps lock status without key press(如何在没有按键的情况下更改大写锁定状态)
问题描述
我正在使用一个在按下 Caps Lock 键时激活的 python 程序,我希望能够在程序处于活动状态时打开/关闭大写锁定状态.
I am using a python program that is activate when pressing Caps Lock key and I want to be able to turn on/off the caps lock status when the program is active.
我尝试使用 virtkey 发送密钥,但它显然不起作用,因为密钥只是激活应用程序并且不会更改大写锁定状态.那么使用 python 实现这一目标的最佳方法是什么?
I tried to send keys with virtkey but it obviously don't work since the keys just activate the app and don't change the caps lock status. So what is the best way to achieve this with python?
我正在使用 Ubuntu
I'm using Ubuntu
推荐答案
在 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)
来源:Benji York - 堆栈内存溢出:在 Python 中更改键盘锁一个>
在 Windows 上:
您应该能够为此使用 SendKeys,如下例所示:
You should be able to use SendKeys for this, as in the following example:
import SendKeys
SendKeys.SendKeys("""
{CAPSLOCK}
""")
这篇关于如何在没有按键的情况下更改大写锁定状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在没有按键的情况下更改大写锁定状态


基础教程推荐
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 包装空间模型 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01