2

In the default example configuration for xbindkeys, there is an example of specifying keycodes directly:

# set directly keycode (here control + f with my keyboard)
#"xterm"
#  c:41 + m:0x4

What do the c: and m: mean? The documentation for xbindkeys does not shed any light on this.

Also, I know you can use xbindkeys -k to find the codes for a key. If that does not work (for one of the nonstandard fn keys, the command does not respond to the keypress and it instead does its normal action), does that mean that xbindkeys cannot handle that key? Even if I know the keycode from showkey -k (217 in my case)?

nog642
  • 133

2 Answers2

2

c:41 + m:0x4 is whatever xbindkeys -k reports when you press the key that you want to bind.

If that does not work (for one of the nonstandard fn keys, the command does not respond to the keypress and it instead does its normal action), does that mean that xbindkeys cannot handle that key?

Probably, yes.

However, there's a chance that you can make it work, depending on what part of the system “steals” the key.

If it's an X11 application, stealing the key is called “grabbing”. Unfortunately, identifying who's grabbing a key is difficult. If you manage to disable the grab then xbindkeys will get its own chance to grab it.

If it's not an X11 application (or even if it is), check the system logs to see if anything is logged when you press the key. If there are any, this will give you a big clue as to who's handling the key press.

Even if I know the keycode from showkey -k (217 in my case)?

That's not the key code you want. showkey shows the Linux keycode, but Xorg has its own keycodes. The Xorg keycodes are normally shifted by 8, to the key code is probably 225. But xbindkeys -k is the way to show the key code, and if that doesn't work, it means xbindkeys can't detect your key.

  • Ah thanks, you're right, something was grabbing the key. I was able to disable the "Search" shortcut in settings (gnome-control-center), which then let xbindkeys -k pick it up. Seems it was m:0x10 + c:255, so the key code was indeed off by 8. Not sure why it's m:0x10 though. – nog642 Mar 14 '24 at 13:21
  • @nog642 0x10 = Mod2 means that NumLock is on, like 0x02 = Lock means that CapsLock is on. – Gilles 'SO- stop being evil' Mar 14 '24 at 13:42
  • Wait, does that mean that m:0x10 + c:255 won't trigger if NumLock is off? I've noticed that all the letters by themselves also have the m:0x10 modifier. I mean this laptop keyboard doesn't have a NumLock key anyway, but if this were on a desktop, it would be weird if the letter "a" with NumLock on and the letter "a" without NumLock off were considered different. – nog642 Mar 15 '24 at 04:54
  • @nog642 Software has to be specially programmed to ignore the NumLock modifier (at least if it's using low-level X11 libraries). I'd expect xbindkeys to handle that because it's a common problem, but I haven't checked. – Gilles 'SO- stop being evil' Mar 15 '24 at 10:11
1

This doesn’t seem to be documented, but the three modifiers b:, c:, and m: introduce numeric values, respectively for mouse buttons, key codes, and the modifier mask. So

c:41 + m:0x4

means “the key with code 41” (f on your keyboard) with modifier 4, i.e. Ctrl. The modifier values are defined in /usr/include/X11/X.h:

/* Key masks. Used as modifiers to GrabButton and GrabKey, results of QueryPointer,
   state in various key-, mouse-, and button-related events. */

#define ShiftMask (1<<0) #define LockMask (1<<1) #define ControlMask (1<<2) #define Mod1Mask (1<<3) #define Mod2Mask (1<<4) #define Mod3Mask (1<<5) #define Mod4Mask (1<<6) #define Mod5Mask (1<<7)

I’m not certain of the answer to your second question, but you should try with c:217.

Stephen Kitt
  • 434,908
  • It would be c:225 because Xorg keycode = Linux keycode + 8 (for reasons). But if xbindkeys -k doesn't report it, xbindkeys won't be able to detect it either. – Gilles 'SO- stop being evil' Mar 13 '24 at 17:48
  • @Gilles'SO-stopbeingevil' I noticed that in /usr/share/X11/xkb/keycodes/evdev. What is the reason? Also about the answer, what are Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, and Mod5Mask? – nog642 Mar 14 '24 at 13:12
  • @nog642 At the time X11 was designed, almost every keyboard had Shift, CapsLock/ShiftLock and Control, but other modifiers were manufacturer-dependent (Alt, Meta, Hyper, Super, … — on a PC today, NumLock and Windows; on a Mac today, Option and Command). So the other modifiers are just called Mod1 to Mod5 and different platforms assign them to differently-named keys. – Gilles 'SO- stop being evil' Mar 14 '24 at 13:40
  • Some keyboards took modifiers to extremes, like the Space Cadet... – Stephen Kitt Mar 14 '24 at 13:52