問題描述
我正在使用一個在按下 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}
""")
這篇關于如何在沒有按鍵的情況下更改大寫鎖定狀態的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!