8

软件修改 Caps Lock 状态

 2 years ago
source link: https://blog.yxwang.me/2010/10/change-caps-lock-state-by-software/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

软件修改 Caps Lock 状态

Tue, Oct 19, 2010 • Tooling

我经常使用的几台电脑中的Caps Lock 键都被我改成了 Ctrl 键,这样修改以后用起 Emacs 来就顺手多了。

最近在 Windows 上用 VMware Remote Control 远登虚拟机调试内核的时候,问题就出来了:可能是这个浏览器插件的 bug,有时键盘的 Caps Lock 会被莫名打开。然后我的这个键盘键位又比较少,不想再让 Caps Lock 键替换另一个用得更少的按键了,于是想到了软件关闭的方法。

搜了下 Stackoverflow 找到个很好用的 Python 库SendKeys,只要两行代码就能在 Windows 下模拟 Caps Lock 按键了:

import SendKeys
SendKeys.SendKeys("{CAPSLOCK}")

另外在 Linux 要模拟按键,可以直接访问 /dev/console:

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)

原问题地址

本作品采用知识共享署名-非商业性使用 3.0 版本许可协议进行许可,欢迎转载,演绎,但是必须保留本文的署名 zellux(包含链接),且不得用于商业目的。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK