I'm running Ubuntu 16.04.1 LTS. I have a remote similar to one here (though mine is just called a "Vista MCE Remote Control") which acts like a keyboard, along with a real keyboard. I'm trying to remap the button on the remote which sends XF86Sleep to send a space instead, but xkbcomp and xmodmap are not behaving as I expect.

First, I tried xkbcomp, as I could give it a device with the -i option:

xid=`xinput list | grep 05a4:9881 | grep keyboard | perl -pe 's/^.*=([0-9]+).*/\1/'`
xkbcomp -i $xid ~/remote.xkb $DISPLAY

I was able to change the key that sends a KP_Multiply to send an underscore no problem by changing:

 key <KPMU> {
     type= "CTRL+ALT",
     symbols[Group1]= [     KP_Multiply,     KP_Multiply,     KP_Multiply,     KP_Multiply,   XF86ClearGrab ]


 key <KPMU> {
     type= "CTRL+ALT",
     symbols[Group1]= [      underscore,      underscore,      underscore,      underscore,   XF86ClearGrab ]

But when I changed the line that said:

 key <I150> {         [       XF86Sleep ] };


 key <I150> {         [           space ] };

this had no effect; hitting the sleep button still put my computer to sleep, even though xev reports the key sends a space (after I wake it up):

KeyRelease event, serial 29, synthetic NO, window 0x1a00001,
     root 0x1d7, subw 0x0, time 1621457, (99,102),  root:(1797,144),
     state 0x0, keycode 150 (keysym 0x20, space), same_screen YES,
     XKeysymToKeycode returns keycode: 65
     XLookupString gives 1 bytes: (20) " "
     XFilterEvent returns: False

Then I tried xmodmap, like this:

% xmodmap -e 'keycode 150 = space'

(This would affect the real keyboard as well, but that's okay as my keyboard doesn't have a sleep button, and if it did I'd want to disable it anyway.) After this, the sleep button does nothing in programs like emacs and konsole---the computer doesn't go to sleep, but there's no space generated---while xev still reports a space (just like above).

Even stranger, I tried this same things with another key, the "home page" key. The xkbcomp scheme sort of works, but any time I use my real keyboard, the key reverts to XF86HomePage until I use another key on the remote. (This doesn't happen with the XF86Sleep key; no matter how may keys I hit on the remote, it still put the computer to sleep unless I do the xmodmap command as well.) On the other hand, in this case the xmodmap command does work, at the minor cost of having the home button on my keyboard also send a space.

Any idea what's going on here, or how I could remap the actual sleep key to space? I've looked at various similar questions here but none seem to match. (Aside from this one, which doesn't have an answer.)


Finally had a chance to try the answer from ssokolow below. Based on the links provided, it ought to have worked. Unfortunately, it doesn't. There are no error messages but there are no changes in the keycodes or keysysms I see in (e.g.) xev.

Here's what I did:

(1) Use lsusb to find the device in question:

Bus 005 Device 002: ID 05a4:9881 Ortek Technology, Inc. IR receiver [VRC-1100 Vista MCE Remote Control]

(2) Use evtest to find the MSC_SCAN codes for a couple of keys:

sudo evtest ... /dev/input/event5: HID 05a4:9881 /dev/input/event6: HID 05a4:9881 ... (Notice two separate /dev/input/events. They keys I'm interested in at the moment are on #6, but trying keys on event5 doesn't work either). They are the "homepage" and "power" keys:

Event: time 1514752612.650320, type 4 (EV_MSC), code 4 (MSC_SCAN), value c0223 Event: time 1514752612.650320, type 1 (EV_KEY), code 172 (KEY_HOMEPAGE), value 1 Event: time 1514752612.650320, -------------- SYN_REPORT ------------ Event: time 1514752612.690312, type 4 (EV_MSC), code 4 (MSC_SCAN), value c0223 Event: time 1514752612.690312, type 1 (EV_KEY), code 172 (KEY_HOMEPAGE), value 0 Event: time 1514752612.690312, -------------- SYN_REPORT ------------ Event: time 1514752615.826339, type 4 (EV_MSC), code 4 (MSC_SCAN), value 10082 Event: time 1514752615.826339, type 1 (EV_KEY), code 142 (KEY_SLEEP), value 1 Event: time 1514752615.826339, -------------- SYN_REPORT ------------ Event: time 1514752615.826366, type 1 (EV_KEY), code 142 (KEY_SLEEP), value 0 Event: time 1514752615.826366, -------------- SYN_REPORT ------------

Build a file /etc/udev/hwdb.d/99-vrc1100-remote.hwdb, carefully making sure there is only one space on the KEYBOARD_KEY lines:

evdev:input:b0003v05a4p9881* KEYBOARD_KEY_10082=playpause KEYBOARD_KEY_C0223=q

I have udev version 229, so one of the links in the answer says this is the correct format (evdev:input:).


sudo systemd-hwdb update

If I run

sudo systemd-hwdb query 'evdev:input:b0003v05a4p9881*'

I get back the last two lines of my file, so this seems to have worked.

I then run:

sudo udevadm trigger --verbose

and I do see what appears to be the relevant devices being printed:

... /sys/devices/pci0000:00/0000:00:1a.2/usb5/5-1/5-1:1.0/0003:05A4:9881.0005/input/input8/event5 /sys/devices/pci0000:00/0000:00:1a.2/usb5/5-1/5-1:1.1/0003:05A4:9881.0006/input/input9/event6 ...

But the keys still don't work. The home page key still produces:

KeyPress event, serial 28, synthetic NO, window 0x4600001, root 0x1d7, subw 0x0, time 8089976, (127,61), root:(998,540), state 0x10, keycode 180 (keysym 0x1008ff18, XF86HomePage), same_screen YES, XLookupString gives 0 bytes: XmbLookupString gives 0 bytes: XFilterEvent returns: False

KeyRelease event, serial 28, synthetic NO, window 0x4600001, root 0x1d7, subw 0x0, time 8090016, (127,61), root:(998,540), state 0x10, keycode 180 (keysym 0x1008ff18, XF86HomePage), same_screen YES, XLookupString gives 0 bytes: XFilterEvent returns: False

The power (sleep) key doesn't seem to do anything. (At some point, I think I managed to disable the sleeping, though I don't remember how.)

I also tried rebooting, that didn't help either. I tried running:

sudo udevadm control --log-priority=debug

After that, I looked through /var/log/syslog but I didn't find anything that looked useful.


The thing to understand is that input handling works like this on Ubuntu:

hardware --scancode--> kernel --keycode--> X11 --> keysym --> application

I had a similar problem and wound up walking my way down the stack and back in time until I found a solution which worked for my 14.04 LTS.

I couldn't get the X11 layer to change things, so I just went down a layer used udev to redefine how the kernel maps scancodes to keycodes.

Since you're on 16.04, you shouldn't need to go as far as I did

(14.04 is in a weird in-between state where it's got the last version of udev listed as requiring an external helper, but it doesn't include that external helper and something I found later suggests that it may actually support the internal way through backported patches... but only with some extra commands to force a config update.)

Here's a summary of the approach that should work in 16.04:

  1. Create an /etc/udev/hwdb.d/whatever.hwdb file according to the format summarized at any of these links: [1] [2] [3] [4] [5]
  2. Run sudo systemd-hwdb update if you have it and sudo udevadm hwdb --update otherwise.
  3. Run sudo udevadm trigger, unplug and replug the device, or reboot.

IMPORTANT: Only use one space to indent the KEYBOARD_KEY_ lines or it will fail silently.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.