50

I'm running XFCE 4.12 on top of Gentoo with a 4.2.0 kernel. My PlayPause button on my keyboard used to work as a global hotkey for VLC. Now VLC won't even recognize the key. It does see "Alt + Media Play Pause" but not the key alone.

Is there a way to see if and what program might be capturing that key?

When I run xdotool key "XF86LogGrabInfo" the tail /var/log/Xorg.0.log file reads

[ 10138.690] (II) Printing all currently active device grabs:
[ 10138.690] (II) End list of active device grabs
3
  • @don_crissti thanks but that doesn't seem to answer anything. Is there another way of registering hotkeys? Commented Feb 10, 2016 at 22:45
  • @don_crissti It's related for sure but I don't think it's a duplicate. Listing all the grabs and finding one specific grabber isn't the same. The solution that's useful to Andrew is buried in a comment (because Andrew's problem isn't what I was asking). Commented Feb 10, 2016 at 22:46
  • Yes running xdotool keydown "XF86AudioPlay"; xdotool key "XF86LogGrabInfo"; xdotool keyup "XF86AudioPlay"; sleep 1; tail /var/log/Xorg.0.log did it. For somehow google Chrome registered the hotkey. Commented Feb 10, 2016 at 23:21

2 Answers 2

32

To find out which app/program grabbed your key use the debug keysym XF86LogGrabInfo. Use xdotool to press keys + XF86LogGrabInfo at the same time e.g. in a terminal run

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

Then check for output with tail /var/log/Xorg.0.log
Note that with gnome 3/gdm and systemd this is no longer logged to Xorg.0.log (it's instead logged to the journal). In that case you could run

journalctl -f

and then in another terminal run the xdotool commands. Switch to the first terminal and you'll see something like

/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

In the above example the program (the client) that grabbed the key is gnome-shell.

How do I figure out what the keys are called?

Check out the manpage of xdotool using man xdotool or an online version, as it lists a number of the special keys. For instance, "alt+r", "Control_L+J", "ctrl+alt+n", "BackSpace". The LinuxQuestions wiki also has a list of X Keysyms one could use. To make things a bit easier, xdotool also has aliases for some of these, such that pressing Shift-Alt-Tab would for instance just be shift+alt+Tab. To verify that this does indeed click that key combination, you could send the input to xev, which is a program that will print whatever key or mouse events it gets to the console. Just do sleep 2; xdotool keydown ${KEY} and switch to the xev window before two seconds has passed to see the keys being clicked on that window. It should then output a series of events, such as these:

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
8
  • Is there something similar for lightdm?
    – elig
    Commented Jun 27, 2019 at 13:35
  • @elig - not sure what you mean... this is done by the X server regardless of your display manager. Commented Jun 27, 2019 at 16:05
  • 2
    Then i don't see it in my logs or journal
    – elig
    Commented Jun 28, 2019 at 12:44
  • Thanks! That saved me a lot of effort! Some small Cinnamon applet suddently took over one my most used shortcuts – I wouldn't have found it without this post.
    – orzechow
    Commented Jul 1, 2021 at 14:25
  • 3
    This answer can be improved by providing a way to determine the name of the key to pass to xdotool as the name of the question is "How do I find out what program 'owns' a hotkey?" and the answer can be made more generic. Commented Aug 18, 2021 at 0:26
3

the following commands helped me to identify all programs grabbing keyboard shortcuts:

$ 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

so in my case the following apps were grabbing key bindings: xinit, unclutter, xscreensaver, firefox, xbindkeys, openbox, copyq, konsole, subl, at-spi2-registryd

2
  • When I do this, I get in each section (under Printing all registered grabs of client...) multiple blocks that each look like grab 0x40700082 (core), type 'KeyPress' on window 0x65b detail 218 (mask 0), modifiersDetail 16 (mask 0) device 'Virtual core keyboard' (3), modifierDevice 'Virtual core keyboard' (3) core event mask 0x3. Does anyone know if this information can be used to determine the affected key (combination)? For example, would 218 and 16 be the keycode and state reported by xev on a keypress event, by any chance? Commented Apr 18 at 0:45
  • Ah, to answer the above, see gist.github.com/CyberShadow/6412d11aea64144f8905cc0b8196f38e (as referenced by unix.stackexchange.com/questions/59141/…). Commented Apr 18 at 0:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .