如何使用 xset 点亮 Caps Lock 指示灯?

发布于 2024-12-08 15:06:42 字数 899 浏览 0 评论 0原文

我编写了一个小 fetchmail 脚本,用于检查远程服务器并在收到新邮件时播放音频文件。我还想在邮件可用时点亮我的键盘灯之一,但我遇到了问题。我可以用这个点亮滚动锁定灯:

/usr/bin/xset led named "Scroll Lock"

但我不能以同样的方式点亮大写锁定:

/usr/bin/xset led named "Caps Lock"

我尝试用数字(1-6)指定按键,但尽管更改了神秘的“LED面罩” (用“xset q”可见)我没有看到灯光有任何变化。

这是因为我将 Caps Lock 键映射为另一个 Ctrl 键而损坏了吗?

在 ~/.Xmodmap 中,我得到:

keycode 66 = Control_L
clear Lock
add Control = Control_L

我不想切换大写锁定,只想切换灯光。有办法做到这一点吗?

进一步说明

这是在 x86 kubuntu lucid 机器上,但我稍后会迁移到 debian。我在 python 守护进程中以非特权用户身份运行该脚本。以 root 身份运行相同的脚本将不起作用,因为 fetchmail 是为我自己配置​​为用户的。最后,这一切都在 tmux 会话中运行。

当我开始这个过程时,我读到了有关 setleds 的信息,但它似乎仅限于非 x 会话中的终端。

以 root 身份登录并运行 'setleds -D +caps < /dev/tty7' 可以工作,但运行 'sudo setleds -D +caps < /dev/tty7' 给我一个权限被拒绝的错误。

xset 命令似乎非常适合我的应用程序,它只是拒绝更改 Caps Lock 指示灯。

I wrote a little fetchmail script that checks the remote server and plays an audio file when I have new mail. I also wanted to also light up one of my keyboard lights when the mail was available but I ran into a problem. I am able to light up the scroll lock light with this:

/usr/bin/xset led named "Scroll Lock"

But I can't light up the Caps Lock in the same way:

/usr/bin/xset led named "Caps Lock"

I tried specifying the key with a number (1-6) but despite changing the mysterious 'LED mask' (visible with 'xset q') I saw no change to the lights.

Is this broken because I've mapped my Caps Lock key as another Ctrl?

In ~/.Xmodmap I've got:

keycode 66 = Control_L
clear Lock
add Control = Control_L

I don't want to toggle caps lock, just the light. Is there a way to do this?

Further Explanation

This is on a x86 kubuntu lucid machine but I will migrate to debian later. I'm running the script as a unprivileged user in a python daemon. Running the same script as root won't work because fetchmail is configured for myself as a user. And finally, this is all run in a tmux session.

When I began this process I read about setleds but it seems to be restricted to terminals in non x sessions.

Logging in as root and running 'setleds -D +caps < /dev/tty7' works but running 'sudo setleds -D +caps < /dev/tty7' gives me a permission denied error.

The xset command seems perfect for my application, it just refuses to change the Caps Lock light.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

简单 2024-12-15 15:06:42

root下执行:

setleds -D +caps setleds -D +caps setleds -D +caps setleds -D +caps /dev/console

很黑客,但对我有用:)

Execute under root:

setleds -D +caps < /dev/console

Hackish, but works for me :)

君勿笑 2024-12-15 15:06:42

是否需要是xset?你用过setleds吗?

setleds -D +caps
setleds -D -caps

简要概述:Linux / Unix 命令:setleds

Does it need to be xset? Have you ever used setleds?

setleds -D +caps
setleds -D -caps

Brief overview: Linux / Unix Command: setleds

蓝咒 2024-12-15 15:06:42

没有 root 权限的 xset

使用 sed 编辑 /usr/share/X11/xkb/compat/ledcaps。无论是否重新启动,此更改都是永久性的。

$ sudo sed -i 's|\!allowExplicit|allowExplicit|g' /usr/share/X11/xkb/compat/ledcaps

注销并再次登录后,现在可以使用以下命令控制 Caps Lock LED,无需任何 root 权限:

$ xset led named 'Caps Lock'
$ xset -led named 'Caps Lock'

xset without root privileges

Edit /usr/share/X11/xkb/compat/ledcaps once using sed. This change remains permanent, regardless of any reboots.

$ sudo sed -i 's|\!allowExplicit|allowExplicit|g' /usr/share/X11/xkb/compat/ledcaps

After logging out and in again, the Caps Lock LED can now be controlled without any root privileges using the commands:

$ xset led named 'Caps Lock'
$ xset -led named 'Caps Lock'
将军与妓 2024-12-15 15:06:42

Caps Lock 指示灯(非功能)关闭

for a in `ls -d /sys/class/leds/*caps*`;do echo 0 >$a/brightness;done

Caps Lock 指示灯(非功能)亮起

for a in `ls -d /sys/class/leds/*caps*`;do echo 1 >$a/brightness;done

Caps Lock led (not the functionality) OFF

for a in `ls -d /sys/class/leds/*caps*`;do echo 0 >$a/brightness;done

Caps Lock led (not the functionality) ON

for a in `ls -d /sys/class/leds/*caps*`;do echo 1 >$a/brightness;done
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文