如何在不按键的情况下更改大写锁定状态 [英] How to change caps lock status without key press

查看:227
本文介绍了如何在不按键的情况下更改大写锁定状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个按Caps Lock键时会激活的python程序,并且我希望能够在该程序处于活动状态时打开/关闭Caps Lock状态.

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}
""")

这篇关于如何在不按键的情况下更改大写锁定状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆