As it turns out the kernel did pick it up, but kept complaining that it's not recognised.
For anyone else having this issue, or wants to map a key that's not read by the OS, read on.
Open a terminal and run dmesg | grep -A 1 -i setkeycodes
. This will give you multiple entries like this:
[ 9.307463] atkbd serio0: Unknown key pressed (translated set 2, code 0xbe on isa0060/serio0).
[ 9.307476] atkbd serio0: Use 'setkeycodes e03e <keycode>' to make it known.
What we are interested is the hexadecimal value after "setkeycodes", in this case this is e03e
. If you have multiple of these, you can run tail -f /var/log/kern.log
. Once you've done so, you can tap the button you're looking for, and this will give you a the same line as above, and again, we only need the hexadecimal value. Make a note of this.
Now run xmodmap -pke | less
and find the appropriate mapping. In my case, I needed to map this to toggle my touch pad, which means I was interested in the following line:
keycode 199 = XF86TouchpadToggle NoSymbol XF86TouchpadToggle
If you can't find whatever you're interested in, read @Gilles answer too, as you can define custom mappings too, then read on (if the kernel reads it, you won't need to add it to xorg.conf.d)
Now I ran the following command: sudo setkeycodes [hexadecimal] [keycode]
, so in my case that became: setkeycodes e03e 199
.
Now you can use the following line to test if it worked and/or you have the correct mapping:
xev | grep -A2 --line-buffered '^KeyRelease' | sed -n '/keycode /s/^.*keycode \([0-9]*\).* (.*, \(.*\)).*$/\1 \2/p'
When you run this command, you need to focus on the newly opened window (xev
) and check the console output. In my case it read as following:
207 NoSymbol
This was obviously wrong, as I requested keycode 199
, so it's mapped to XF86TouchpadToggle
. I checked xmodmap -pke
again, and noticed that keycode 207
is actually mapped to NoSymbol
, and I noticed that there was an offset difference of 8, so I tried the setkeycodes
command again, but the key is mapped to keycode 191
.
sudo setkeycodes e03e 191
This worked perfectly.
EDIT -- the solution I provided to have to working on start up does not. I will figure this out tomorrow and update this answer. For now I suppose you can run this on start up manually.
Best Answer
I found out that I need to send an EVIOCGRAB ioctl to the device, which grabs it for exclusive use.
Here's how to do it in Ruby:
Note: You'll need to install the
libdevinput
gem,ffi
, and Linux headers. If you are using a Linux version between3.2.0
and3.6.11
, you can replace theFFI::ConstGenerator
part withEVIOCGRAB = 1074021776
, and then you don't needffi
or Linux headers.