Logitech K400r and the missing middle mouse button

Recently I bought me a new wireless keyboard. Reason was the advice of my physiotherapist to improve my sitting posture at work, so she told me to place the monitor in eye level and the keyboard and mouse near the edge of the desk. But this is not really easy with a notebook. Therefore I searched for a lightweight keyboard with an integrated touchpad: Logitech K400r won the selection.
The keyboard is small so I need to getting used to it but it worked out of the box even on my new installed linux arch distribution. Only one thing was annoying: the missing middle mouse button. I need this little helper so much on a linux system, think only about the handy copy&paste function …

After asking google for help I was a little bit disappointed, because “neojam” [1] wasn’t able to activate/find a way to use the middle mouse button. But I was willing to find a way.

First of all I thought about the possibility to map keys with xmodmap. So I started xev to realize the proper code for the middle mouse button. This approach led to nowhere, because clicking both mouse buttons on my laptop was indicated as “button2” but not on the K400r, there I got only “button1” and “button3”. So I searched for a possibility to map the simultanouse clicking of both buttons. I found the hint to use the “Emulate3Buttons”-Option in the xorg.conf. The default set of this configuration is disabled, but I didn’t want to enable it for the generic mouse InputDevice. This site [2] helped me to remember the “MatchProduct”-Option for special configuration of InputClasses in the xorg.conf. With the xinput list command I got this output:

$ xinput list
⎡ Virtual core pointer                        id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                  id=4    [slave  pointer  (2)]
⎜   ↳ SynPS/2 Synaptics TouchPad                  id=10    [slave  pointer  (2)]
⎜   ↳ TPPS/2 IBM TrackPoint                       id=11    [slave  pointer  (2)]
⎜   ↳ Logitech Unifying Device. Wireless PID:4024    id=13    [slave  pointer  (2)]
⎣ Virtual core keyboard                       id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard                 id=5    [slave  keyboard (3)]
    ↳ Power Button                                id=6    [slave  keyboard (3)]
    ↳ Video Bus                                   id=7    [slave  keyboard (3)]
    ↳ Sleep Button                                id=8    [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard                id=9    [slave  keyboard (3)]
    ↳ ThinkPad Extra Buttons                      id=12    [slave  keyboard (3)]

So I only had to add this stuff to my xorg.conf:

Section "InputClass"
    Identifier      "Logitech K400r"
    MatchProduct    "Logitech Unifying Device. Wireless PID:4024"
    Option          "Emulate3Buttons" "yes"

And finally my precious middle mouse button worked also on my new keyboard 😎

[1] http://forums.logitech.com/t5/Keyboards-and-Keyboard-Mice/Disappointed-with-my-new-K400r-keyboard/td-p/948530
[2] https://wiki.archlinux.org/index.php/Xorg

4 thoughts on “Logitech K400r and the missing middle mouse button

  1. Robert

    Just wanted to say thanks for figuring this out! Now if we just had a way to toggle the default state for the fn key so that F1-F12 were the default instead of the media/app keys..

  2. David Ozog

    Awesome! This works from an Ubuntu VirtualBox guest machine too. I just had to replace the MatchProduct line with:
    MatchProduct “ImExPS/2 Generic Explorer Mouse”

    Thanks for figuring this out for me! I *need* that middle mouse button paste, man…

  3. Anonymus

    This is currently the correct approach for most common distros. Worked instantly. Directly copied of stackexchange. I am not the author.


    You can set this property with xinput. Run xinput list

    to see the list of connected input devices. Note the exact name or the number of the device corresponding to your mouse (not the “Virtual core pointer”, but something like “Logitech USB-PS/2 Mouse M-BA47”). The name depends on your mouse model; I think the number is assigned dynamically, so you might need to do a bit of parsing to cope with multiple machines.

    Then, run

    xinput set-prop “$device_name_or_number” “Evdev Middle Button Emulation” 1

    Run xinput list-props “$device_name_or_number” to see a list of available properties, the exact set is different on different systems.

    While you’re at it, you might want to tune other settings (run xinput list-props “$device_name_or_number” to see what settings exist). In particular, by default, I think the emulated middle button will be the same as the mouse wheel press, but that should be fixable by reassigning the wheel button (Evdev Wheel Emulation Button).

    See also Configuring Input Devices on the Ubuntu wiki.


Leave a Reply

Your email address will not be published. Required fields are marked *