有人知道如何在Python中切换大写锁定吗? [英] Anybody know how to toggle caps lock on/off in Python?
本文介绍了有人知道如何在Python中切换大写锁定吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当两个切换按钮按住一秒钟时,我试图切换大写锁定的开/关.我试过使用virtkey模块,但是它不起作用.该模块确实可以用于其他键,所以我认为我使用的模块不正确.
I'm trying to toggle caps lock on/off when the two shift buttons are held down for a second. I've tried using the virtkey module, but it's not working. That module does work for other keys though, so I don't think I'm using the module incorrectly.
有人能做到这一点吗?
请清楚一点,我实际上想打开/关闭大写锁定,而不仅仅是LED.
Just to be clear, I want to actually toggle caps lock on/off and not just the LED.
谢谢!
推荐答案
这对我有用(打开和关闭led以及启用/禁用上限)
This works for me (turns the led on and off as well as enable/disable caps)
import virtkey
v = virtkey.virtkey()
v.press_keycode(66)
v.release_keycode(66) # first release doesn't release it
v.release_keycode(66)
还有更多示例
v.press_keycode(66) # turns capslock on
v.release_keycode(66)
v.press_keycode(66) # turns capslock off
v.release_keycode(66)
您也可以仅使用release_keycode来获得类似行为的切换
You can also get a toggle like behaviour just using release_keycode
v.release_keycode(66) # toggles capslock
v.release_keycode(66) # toggles back again capslock
这篇关于有人知道如何在Python中切换大写锁定吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文