Ubuntu 没有为某些媒体键提供正确的键码

Yep*_*_Me 5 sound keyboard i3-wm media-buttons 16.04

我刚刚在 ThinkPad T450 上安装了 Ubuntu 16.04,由于某种原因,音量和屏幕亮度的媒体键没有提供任何键码或键符号(即 XF86AudioRaiseVolume)。但所有其他媒体键都会给出正确的值。

奇怪的是,媒体键在 unity 和 gnome 中仍然工作正常,这只是我使用 i3 时的问题,因为我无法映射音量键来更改音量。

这是xev音量减小、音量增大和音量静音键返回的内容:

音量减小:

FocusOut event, serial 33, synthetic NO, window 0x1a00001,
    mode NotifyUngrab, detail NotifyPointer

FocusIn event, serial 33, synthetic NO, window 0x1a00001,
    mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 33, synthetic NO, window 0x0,
    keys:  2   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   


0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0 
Run Code Online (Sandbox Code Playgroud)

提高音量:

FocusOut event, serial 33, synthetic NO, window 0x1a00001,
    mode NotifyGrab, detail NotifyAncestor

FocusIn event, serial 33, synthetic NO, window 0x1a00001,
    mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 33, synthetic NO, window 0x0,
    keys:  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   
Run Code Online (Sandbox Code Playgroud)

音量静音:

FocusOut event, serial 33, synthetic NO, window 0x1a00001,
    mode NotifyUngrab, detail NotifyPointer

FocusIn event, serial 33, synthetic NO, window 0x1a00001,
    mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 33, synthetic NO, window 0x0,
    keys:  2   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0 
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,它们都是一样的。所以我不知道 unity 或 gnome 如何区分它们。仅供参考,我将显示麦克风关闭和 wifi 关闭媒体键的输出xev

KeyRelease event, serial 33, synthetic NO, window 0x1a00001,
    root 0xf6, subw 0x0, time 3107820, (-19,759), root:(625,798),
    state 0x0, keycode 198 (keysym 0x1008ffb2, XF86AudioMicMute), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyPress event, serial 34, synthetic NO, window 0x1a00001,
    root 0xf6, subw 0x0, time 3112189, (-19,759), root:(625,798),
    state 0x0, keycode 246 (keysym 0x1008ff95, XF86WLAN), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False
Run Code Online (Sandbox Code Playgroud)

在安装 ubuntu 之前,我也曾获得过类似的音量键结果(我使用的是 Arch)。

亮度键也不起作用,这些键是否在某个低级别被覆盖?有没有一种方法可以修复它,以便它们返回正确的值,或者有其他方法可以让媒体密钥在 ubuntu 上工作吗?

更新:这就是xev我在运行 Unity 时提供的音量增大和减小键。

FocusOut event, serial 47, synthetic NO, window 0x4800001,
    mode NotifyGrab, detail NotifyAncestor

FocusIn event, serial 47, synthetic NO, window 0x4800001,
    mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 47, synthetic NO, window 0x0,
    keys:  2   0   0   0   0   0   0   0   0   0   0   0   0   0   0   4   
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   

KeyRelease event, serial 47, synthetic NO, window 0x4800001,
    root 0xf7, subw 0x0, time 2182026, (-1217,972), root:(525,2104),
    state 0x0, keycode 122 (keysym 0x1008ff11, XF86AudioLowerVolume), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

FocusOut event, serial 47, synthetic NO, window 0x4800001,
    mode NotifyGrab, detail NotifyAncestor

FocusIn event, serial 47, synthetic NO, window 0x4800001,
    mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 47, synthetic NO, window 0x0,
    keys:  2   0   0   0   0   0   0   0   0   0   0   0   0   0   0   8   
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   

KeyRelease event, serial 47, synthetic NO, window 0x4800001,
    root 0xf7, subw 0x0, time 2185429, (-1217,972), root:(525,2104),
    state 0x0, keycode 123 (keysym 0x1008ff13, XF86AudioRaiseVolume), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False
Run Code Online (Sandbox Code Playgroud)

运行 unity 时,我还有unity-settings-daemon,unity-panel-serviceunity-fallback-mount-helper。其中之一可以捕获事件并添加XF86按键符号吗?这些都没有在 i3 中运行。

为了回应@Adaephon,我的 i3 配置中有这个:

# volume controls
bindsym XF86AudioRaiseVolume exec amixer -q  set Master playback 2%+ unmute
bindsym XF86AudioLowerVolume exec amixer -q  set Master playback 2%- unmute
bindsym XF86AudioMute exec amixer -q set Master mute
Run Code Online (Sandbox Code Playgroud)

Ada*_*hon 6

看起来有问题的密钥已经被其他应用程序全局获取。您获得的三段输出xev仅与 xev 窗口失去和重新获取焦点有关,而按键则被抓住(请参阅我关于旧i3 FAQ的帖子)。

有两个可能的原因,为什么xev可能会显示这样的输出并且键绑定不起作用:

  1. 首先,我会检查有问题的键 - XF86AudioLowerVolume(keycode 122)、XF86AudioRaiseVolume(keycode 123) 和XF86AudioMute(keycode 121) - 是否已在您的i3bindsym配置中与(或bindcode)绑定。也许只是绑定的命令,不起作用。

    (更新)从你的i3配置片段来看,情况似乎如此。我认为 16.04 默认使用 PulseAudio,因此amixer可能没有安装。您可以使用pactlPulseAudio 来更改音量。要模拟您之前的amixer设置,请尝试以下操作:

    bindsym XF86AudioRaiseVolume exec pactl set-sink-volume @DEFAULT_SINK@ +2%; exec pactl set-sink-mute @DEFAULT_SINK@ 0
    bindsym XF86AudioLowerVolume exec pactl set-sink-volume @DEFAULT_SINK@ -2%; exec pactl set-sink-mute @DEFAULT_SINK@ 0
    bindsym XF86AudioMute exec pactl set-sink-mute @DEFAULT_SINK@ toggle
    
    Run Code Online (Sandbox Code Playgroud)

    如果您只想使用和键取消静音,也可以使用on1来代替。toggleset-sink-muteXF86AudioLowerVolumeXF86AudioRaiseVolume

  2. 如果情况并非如此,则其他一些工具正在获取这些密钥。一个可能的候选人是gnome-settings-daemonunity-settings-daemon也可能是另一个。此外,某些媒体播放器可能会尝试全局绑定这些键。ps aux我建议检查新i3会话的输出,以查看自动启动的内容。当你找到罪魁祸首时,你基本上有三个选择:

    • 在大多数情况下,应该可以取消配置键绑定。如果您想继续使用抓住钥匙的任何东西,这可能是最简单的解决方案。
    • 使其正常工作。也许程序抓取按键实际上应该做你想做的事情(例如音量控制),但由于某种原因它不能。例如:程序尝试使用 PulseAudio 更改音量,而您实际上并未使用 PulseAudio。
    • 阻止它开始。如果您自己将其设置为自动启动(例如i3exec配置中的语句),则可以将其删除。如果由于某些 Ubuntu 预设而自动启动,则可能需要更多工作。

您可以使用我(其他)关于旧i3 常见问题解答gnome-settings-daemon的帖子中的说明:

您应该能够使用以下命令获取绑定键的列表:

gsettings list-recursively org.gnome.settings-daemon.plugins.media-keys
Run Code Online (Sandbox Code Playgroud)

然后您可以通过分配空字符串来取消设置它们

gsettings set org.gnome.settings-daemon.plugins.media-keys volume-mute ''
gsettings set org.gnome.settings-daemon.plugins.media-keys volume-down ''
gesttings set org.gnome.settings-daemon.plugins.media-keys volume-up ''
Run Code Online (Sandbox Code Playgroud)

或者,您也可以使用dconf

dconf write /org/gnome/settings-daemon/plugins/media-keys/volume-mute "''"
dconf write /org/gnome/settings-daemon/plugins/media-keys/volume-down "''"
dconf write /org/gnome/settings-daemon/plugins/media-keys/volume-up "''"
Run Code Online (Sandbox Code Playgroud)