1

I have a graphics tablet, that acts as two USB devices on Ubuntu 20.04. One pointing device and one keyboard device for the hardware buttons. (The tablet does not use the wacom driver, so I cannot use the usual graphics tablet utilities)

The keyboard driver sends Shortcuts like Ctrl-z, and maybe also own keycodes for it. I would like to remap the buttons to other shortcuts. Is there a way to capture the keys from only one specific keyboard and remap them under X11?

Xmodmap and similar configuration files and tools seem to apply to all keyboards, but I wonder if there are options for per-device configuration. A tool that captures keys from the keyboard device and then sends the new shortcut to the active window would also be an acceptable solution for me.

I am looking for general advice that works for USB keyboards (and does not need to be tested with anything else than a standard USB keyboard). I will adapt it to my use-case myself to avoid making this question overly specific.

0

2 Answers 2

1

You could look at a tool like KeyFuzz, which will do exactly what you're looking for. The learning curve is a little steep at first, but with a little help from evtest (to find the scan and key codes for your specific keyboard), you can set up a custom remapping for just the one keyboard.

Notes:

  • The latest version of KeyFuzz (0.2 as of this writing) was last updated in January 2006, but the code still compiles just fine on Ubuntu 20.04. I speak from experience on this.

  • The evtest tool can be installed like this:

    $ sudo apt install evtest
    

    From there you can use it by calling the tool with sudo:

    $ sudo evtest
    

    This will give you something like:

    No device specified, trying to scan all of /dev/input/event*
    Available devices:
    /dev/input/event0:   Sleep Button
    /dev/input/event1:   Lid Switch
    /dev/input/event2:   Power Button
    /dev/input/event3:   AT Translated Set 2 keyboard
    /dev/input/event4:   Video Bus
    /dev/input/event5:   HDA Intel PCH Mic
    /dev/input/event6:   HDA Intel PCH Headphone
    /dev/input/event7:   HDA Intel PCH HDMI/DP,pcm=3
    /dev/input/event8:   HDA Intel PCH HDMI/DP,pcm=7
    /dev/input/event9:   HDA Intel PCH HDMI/DP,pcm=8
    /dev/input/event10:  HDA Intel PCH HDMI/DP,pcm=9
    /dev/input/event11:  HDA Intel PCH HDMI/DP,pcm=10
    /dev/input/event12:  ThinkPad Extra Buttons
    /dev/input/event13:  Integrated IR Camera: Integrate
    /dev/input/event14:  Integrated Camera: Integrated C
    /dev/input/event15:  Synaptics TM3289-002
    /dev/input/event16:  TPPS/2 Elan TrackPoint
    Select the device event number [0-16]:
    

    Choosing a device will then print the keymap to the screen and pressing keys will then show individual details about each press:

    Event: time 1612367786.809999, type 4 (EV_MSC), code 4 (MSC_SCAN), value 21
    Event: time 1612367786.809999, type 1 (EV_KEY), code 33 (KEY_F), value 1
    Event: time 1612367786.809999, -------------- SYN_REPORT ------------
    

    With this, you can create your custom mapping document for KeyFuzz.

4
  • I'll look into it. Does it also stop the standard keys (e.g. ctrl-z) from being sent?
    – allo
    Feb 3, 2021 at 16:55
  • 1
    The signal is translated before it gets through the input buffer so, yes. If you map [Z] to [PgUp], then your [Ctrl]+[Z] will be seen as [Ctrl]+[PgUp] by the OS, but only for the keyboard you remap.
    – user1091774
    Feb 3, 2021 at 16:58
  • That's a problem. I'd like to remove, for example, the ctrl-key from one sequence, but keep it in another one. For what keyfuzz is doing I found a way to use udev hwdb files, which probably achives the same, but does not allow for changing, e.g., ctrl-z to a single key like just a. Maybe I will need a more advanced solution than just remapping keys.
    – allo
    Feb 5, 2021 at 18:33
  • To map a single key to do many things, you could look at AutoKey. The downside is that this would apply to all keyboards, not just a specific device 🤔
    – user1091774
    Feb 5, 2021 at 23:19
1

One way to remap keys in a 1:1 manner is using udev hwdb files, like the one shipped with systemd

This allows for matching a device and then remapping keys. It does not allow for remapping sequences, so ctrl-z can be mapped to ctrl-a, but not to just a.

Example from the linked file:

evdev:atkbd:dmi:bvn*:bvr*:bd*:svnAcer*:pn*
evdev:atkbd:dmi:bvn*:bvr*:bd*:svnGateway*:pnA0A1*:pvr*
evdev:atkbd:dmi:bvn*:bvr*:bd*:svneMachines:pneMachines*E725:pvr*
 KEYBOARD_KEY_a5=help                                   # Fn+F1
 KEYBOARD_KEY_a6=setup                                  # Fn+F2 Acer eSettings
 KEYBOARD_KEY_a7=battery                                # Fn+F3 Power Management
 KEYBOARD_KEY_a9=switchvideomode                        # Fn+F5
 KEYBOARD_KEY_b2=www
 KEYBOARD_KEY_b3=euro
 KEYBOARD_KEY_b4=dollar

The device IDs can for example be found using the evtest program, which lists all input devices. One can then useevdev:name:My*Keyboard*Manufacturer*Model to match input devices wit My Keyboard Manufacturer Model

valid key codes can be found with the command

sed -n '/KEY_/{s/.*KEY_\([A-Za-z0-9_]\+\).*/\L\1/g;p}' /usr/include/linux/input-event-codes.h | less

The file then needs to be installed into /etc/udev/hwdb.d/myrules.hwdb

So this is no full solution for the question yet, but may already help people with similar problems, who do not need a solution that can rewrite sequences of keys.

You must log in to answer this question.

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