如何找出哪个程序“拥有”热键?

如何找出哪个程序“拥有”热键?

我在 Gentoo 上运行 XFCE 4.12,内核为 4.2.0。我键盘上的 PlayPause 按钮​​曾经用作 VLC 的全局热键。现在 VLC 甚至无法识别密钥。它确实看到“Alt + 媒体播放暂停”,但没有看到单独的键。

有没有办法查看是否以及什么程序可能捕获该密钥?

当我运行xdotool key "XF86LogGrabInfo"文件时tail /var/log/Xorg.0.log读取

[ 10138.690] (II) Printing all currently active device grabs:
[ 10138.690] (II) End list of active device grabs

答案1

要找出哪个应用程序/程序获取了您的密钥,请使用调试键符号XF86LogGrabInfo。用于同时xdotool按 + 键,例如在终端运行中XF86LogGrabInfo

KEY=XF86AudioPlay
xdotool keydown ${KEY}; xdotool key XF86LogGrabInfo; xdotool keyup ${KEY} 

然后使用tail /var/log/Xorg.0.log
Note that with 检查输出,gnome 3/gdm并且systemdthis 不再记录到Xorg.0.log(而是记录到杂志)。在这种情况下你可以运行

journalctl -f

然后在另一个终端中运行xdotool命令。切换到第一个终端,你会看到类似的内容

/usr/lib/gdm/gdm-x-session[629]: Active grab 0x40c0a58e (xi2) on device 'Virtual core keyboard' (3):
/usr/lib/gdm/gdm-x-session[629]: client pid 708 /usr/bin/gnome-shell
/usr/lib/gdm/gdm-x-session[629]: at 32595124 (from passive grab) (device frozen, state 6)
/usr/lib/gdm/gdm-x-session[629]: xi2 event mask for device 3: 0xc000
/usr/lib/gdm/gdm-x-session[629]: passive grab type 2, detail 0xac, activating key 172

在上面的例子中,获取密钥的程序(客户端)是gnome-shell

我如何知道这些键的名称?

查看xdotool使用man xdotool或的联机帮助页网络版,因为它列出了许多特殊键。例如,“alt+r”、“Control_L+J”、“ctrl+alt+n”、“BackSpace”。 LinuxQuestions wiki 也有X 键符号列表一个可以使用。为了让事情变得更简单,xdotool其中一些还具有别名,例如按 Shift-Alt-Tab 就可以了shift+alt+Tab。要验证这确实单击了该组合键,您可以将输入发送到xev,该程序会将其获得的任何键或鼠标事件打印到控制台。只需在两秒过去之前sleep 2; xdotool keydown ${KEY}切换到该xev窗口即可看到在该窗口上单击的按键。然后它应该输出一系列事件,例如:

PropertyNotify event, serial 168, synthetic NO, window 0x1e00001,
    atom 0x13e (_GTK_EDGE_CONSTRAINTS), time 4390512, state PropertyNewValue

MappingNotify event, serial 168, synthetic NO, window 0x0,
    request MappingKeyboard, first_keycode 8, count 248

KeyPress event, serial 168, synthetic NO, window 0x1e00001,
    root 0x163, subw 0x0, time 4390719, (882,657), root:(1000,771),
    state 0x0, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyPress event, serial 169, synthetic NO, window 0x1e00001,
    root 0x163, subw 0x0, time 4390738, (882,657), root:(1000,771),
    state 0x8, keycode 23 (keysym 0xff09, Tab), same_screen YES,
    XLookupString gives 1 bytes: (09) " "
    XmbLookupString gives 1 bytes: (09) "   "
    XFilterEvent returns: False

答案2

以下命令帮助我识别所有占用键盘快捷键的程序:

$ lsof -c Xorg | grep ".log" # find out the path for the Xorg log file
Xorg    16025   sr    4w      REG              254,1    225839 3933229 /home/sr/.local/share/xorg/Xorg.0.log
$ xdotool key XF86LogGrabInfo # prints all Xorg registered grabs
$ cat /home/sr/.local/share/xorg/Xorg.0.log | grep grabs
[ 39303.019] (II) Printing all currently active device grabs:
[ 39303.019] (II) End list of active device grabs
[ 39303.019] Printing all currently registered grabs
[ 39303.019]   Printing all registered grabs of client pid 16024 xinit /home/sr/.xinitrc -- /etc/X11/xinit/xserverrc :0 vt1 -keeptty -auth /tmp/serverauth.6AO52I3zhe
[ 39303.019]   Printing all registered grabs of client pid 16045 unclutter 
[ 39303.019]   Printing all registered grabs of client pid 16047 xscreensaver 
[ 39303.019]   Printing all registered grabs of client pid 16109 /usr/lib/firefox/firefox 
[ 39303.019]   Printing all registered grabs of client pid 16055 xscreensaver-systemd 
[ 39303.019]   Printing all registered grabs of client pid 16057 xbindkeys 
[ 39303.027]   Printing all registered grabs of client pid 16039 /usr/bin/openbox --startup /usr/lib/openbox/openbox-autostart OPENBOX
[ 39303.039]   Printing all registered grabs of client pid 16048 copyq 
[ 39303.039]   Printing all registered grabs of client pid 16049 konsole 
[ 39303.039]   Printing all registered grabs of client pid 16095 /usr/bin/copyq --clipboard-access monitorClipboard
[ 39303.039]   Printing all registered grabs of client pid 16109 /usr/lib/firefox/firefox 
[ 39303.039]   Printing all registered grabs of client pid 16456 subl --detached
[ 39303.039]   Printing all registered grabs of client pid 16465 /usr/lib/at-spi2-registryd --use-gnome-session
[ 39303.039]   Printing all registered grabs of client pid 17178 xdotool key XF86LogGrabInfo
[ 39303.039] End list of registered passive grabs

所以在我的例子中,以下应用程序正在获取按键绑定:xinit、unclutter、xscreensaver、firefox、xbindkeys、openbox、copyq、konsole、subl、at-spi2-registryd

相关内容