当前位置: 首页>>技术教程>>正文


xorg – 关键代码如何映射到适当的操作?

, ,

问题描述

在弄清楚如何使用 udev 更改扫描代码到按键代码的映射后,请参阅 this question ,我想知道如何将这些按键代码(或事件,如果您愿意)映射到适当的操作。

因此,例如,如果您在键盘上按 volume up,则会发送一个扫描代码,然后该扫描代码将转换为 volumeup 键代码。但是这个关键代码是如何被拦截、调高音量并显示相应的通知的呢?

我的猜测是必须在某个地方调用脚本,所以我想知道这些脚本在哪里。

编辑:我提到的关键代码不要与 xev 返回的关键代码混淆,但我也对这些感兴趣;)

最佳方案

好的,在 https://help.ubuntu.com/community/MultimediaKeys 找到了这个

\\n

When you hit a key on your keyboard, the linux kernel generates a raw\\n scancode for it (if it is assigned). Each scancode can be mapped to a\\n keycode. This is at kernel level. X has a (quasi) total independent\\n way of mapping keys: X reads the kernel keycode table at startup, then\\n maps the keycode to its independent keycode table (it is the same as\\n the kernel keycodes but different :)). Then each keycode can be mapped\\n to a keysym, i.e. a string which represent a key or suggest an action.\\n Thus to have our keys fully functional, they need a kernel\\n scancode/keycode plus a X keycode/keysym. It may seem weird, but X\\n developers have their reason to keep a separate keyboard mapping from\\n the kernel. It is not difficult at all, just a quite tedious\\n procedure.

\\n

所以键码被映射到键符号,那么键符号在哪里?我从这个问题中找到并回答:Where do I find a list of all X keysyms these days? 由于我们正在讨论音量键,因此可以在答案中提到的 source-code 中的 XF86keysym.h 中找到它。

在我计算机上的该文件中,我找到了以下卷:

#define XF86XK_AudioLowerVolume 0x1008FF11   /* Volume control down        */
#define XF86XK_AudioMute    0x1008FF12   /* Mute sound from the system */
#define XF86XK_AudioRaiseVolume 0x1008FF13   /* Volume control up          */

奇怪……与其他任何东西不同的值,也许有多个系统来处理密钥? http://crunchbang.org/forums/viewtopic.php?id=16656


我正在使用 Xubuntu,为了控制按键,我需要手动映射操作(如 How do I change my keyboard shortcuts in xubuntu? )。然而,这些通知似乎是独立的,就好像它们在 key-press 上接收并相应地执行操作一样,这可能意味着 Ubuntu 中的其他程序都是以这种方式设置的,因此不需要将脚本映射到按键。

所以我非常确定程序现在正在获取密钥(因此找不到任何脚本)。

在 Xubuntu 中,我遇到了 Pulse Audio 的问题,并使用自定义脚本来更改音量,似乎 Pulse 正在拦截静音键,Mute key mutes Alsa and PulseAudio, but unmutes only Alsa 提供了有趣的解决方法。


查看有关 NotifyOSD https://wiki.ubuntu.com/NotifyOSD#Volume_changes 的信息

如果您查看这些图表:https://wiki.ubuntu.com/NotifyOSD#Architecture

尤其是这个:\n

它显示有一个“硬件按键侦听器”,它接收来自 DBus 或 HAL 的信息?\n然后它“从系统检索视觉元素”,其中声音和亮度图标位于 Notify-OSD 的源中,然后从那里制作气泡。


这一切都非常令人困惑,但据我了解(到目前为止):

原始扫描码(例如 e016)>键码(例如 160)> keysym(例如 XF86AudioMute)> gnome-settings-daemon(例如volume-up)> DBus信号> hardware-keys-listener for notify-osd(或其他程序监听)

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/14401.html,未经允许,请勿转载。