How do I remap the search button on my Logitech MX400?

I have a logitech MX400 wireless. It has a search button I would like to use for pasting (instead of the extremely sensitive but hard to press scroll wheel). I already remapped other buttons with xbindkeys, and used xev to find the button press code, but this does not work for the search button. using xev and clicking the search button I get the following events

FocusOut event, serial 34, synthetic NO, window 0x3c00001,
    mode NotifyGrab, detail NotifyAncestor

FocusIn event, serial 34, synthetic NO, window 0x3c00001,
    mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 34, synthetic NO, window 0x0,
    keys:  4294967275 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   

PropertyNotify event, serial 34, synthetic NO, window 0x3c00001,
    atom 0x1d7 (_NET_WM_ICON_GEOMETRY), time 23653064, state PropertyNewValue

No ButtonPress events. It seems that the search button is intercepted at a level below the X events. Any ideas? I have ubuntu 12.04. Ubuntu actually sees the click and spawns a search dialog, but there's no trace of a click event in the xev.

Edit

I checked the method provided with xmodmap. My .Xmodmap now contains the following line

keycode 225 = XF86Paste NoSymbol XF86Paste``

running xmodmap ~/.Xmodmap now disables the button altogether (or at least, I don't get any result by pressing it). I tried xmodmap -pke and it prints out:

keycode 225 = XF86Paste NoSymbol XF86Paste NoSymbol XF86Paste

Strange enough. All the other entries are similarly formatted. I am close to the solution, but there's still something weird.

Edit 2

I tried to run xinput (never heard of this command. amazing stuff). There are two entries for Logitech. Here is the output of listing each of them (id 9 and 10)

Logitech USB Receiver                       id=9    [slave  pointer  (2)]
    Reporting 7 classes:
        Class originated from: 9. Type: XIButtonClass
        Buttons supported: 24
        Button labels: "Button Left" "Button Middle" "Button Right" "Button Wheel Up" "Button Wheel Down" "Button Horiz Wheel Left" "Button Horiz Wheel Right" "Button Side" "Button Extra" "Button Forward" "Button Back" "Button Task" "Button Unknown" "Button Unknown" "Button Unknown" "Button Unknown" "Button Unknown" "Button Unknown" "Button Unknown" "Button Unknown" "Button Unknown" "Button Unknown" "Button Unknown" "Button Unknown"
        Button state:
        Class originated from: 9. Type: XIValuatorClass
        Detail for Valuator 0:
          Label: Rel X
          Range: -1.000000 - -1.000000
          Resolution: 1 units/m
          Mode: relative
        Class originated from: 9. Type: XIValuatorClass
        Detail for Valuator 1:
          Label: Rel Y
          Range: -1.000000 - -1.000000
          Resolution: 1 units/m
          Mode: relative
        Class originated from: 9. Type: XIValuatorClass
        Detail for Valuator 2:
          Label: Rel Horiz Wheel
          Range: -1.000000 - -1.000000
          Resolution: 1 units/m
          Mode: relative
        Class originated from: 9. Type: XIValuatorClass
        Detail for Valuator 3:
          Label: Rel Vert Wheel
          Range: -1.000000 - -1.000000
          Resolution: 1 units/m
          Mode: relative
        Class originated from: 9. Type: XIScrollClass
        Scroll info for Valuator 2
          type: 2 (horizontal)
          increment: 1.000000
          flags: 0x0
        Class originated from: 9. Type: XIScrollClass
        Scroll info for Valuator 3
          type: 1 (vertical)
          increment: -1.000000
          flags: 0x2 ( preferred )


Logitech USB Receiver                       id=10   [slave  pointer  (2)]
    Reporting 6 classes:
        Class originated from: 10. Type: XIButtonClass
        Buttons supported: 7
        Button labels: "Button 0" "Button Unknown" "Button Unknown" "Button Wheel Up" "Button Wheel Down" "Button Horiz Wheel Left" "Button Horiz Wheel Right"
        Button state:
        Class originated from: 10. Type: XIKeyClass
        Keycodes supported: 248
        Class originated from: 10. Type: XIValuatorClass
        Detail for Valuator 0:
          Label: Rel X
          Range: -1.000000 - -1.000000
          Resolution: 1 units/m
          Mode: relative
        Class originated from: 10. Type: XIValuatorClass
        Detail for Valuator 1:
          Label: Rel Y
          Range: -1.000000 - -1.000000
          Resolution: 1 units/m
          Mode: relative
        Class originated from: 10. Type: XIValuatorClass
        Detail for Valuator 2:
          Label: Rel Horiz Wheel
          Range: -1.000000 - -1.000000
          Resolution: 1 units/m
          Mode: relative
        Class originated from: 10. Type: XIScrollClass
        Scroll info for Valuator 2
          type: 2 (horizontal)
          increment: 1.000000
          flags: 0x0

Testing device 9 does not do anything with the button. Testing device 10 instead works, and this is the output as I click

$ xinput test 10
key press   225 
key release 225 
key press   225 
key release 225 
key press   225 
key release 225

So it appears that the mouse acts as a keyboard in this regard, but for some reason, xmodmap does not do anything when it receives key 225.

** Edit **

I can confirm that adding keycode 225 = a prints an a every time I click the button. So the problem seems to be related to how XF86Paste is actually handled. I am sending it, but it's not pasting.


To simulate keyboard events I suggest you the great tool xdotool Install xdotool.

1. Install xdotool via terminal (CTRL+ALT+T):

sudo apt-get install xdotool

or use the Software Center Install xdotool.

2. Create a script that uses xdotool to emulate the key down events of CTRL and v. In the terminal:

mkdir -p ~/bin  
gedit ~/bin/fakepaste

Copy the following content into the editor window that opened up. After copying the code save, then close it:

#!/bin/sh
exec /usr/bin/xdotool key CTRL+V  
EOF

Now make the script executable:

chmod +x ~/bin/fakepaste

3. Log out and log in to reload your PATH.

4. Create the custom shortcut

Go to System Settings, then go to Keyboard, then Shortcuts.

Press the + button at the bottom of the dialog. Provide a name for the shortcut you're about to create and for the command fill in: fakepaste. Press OK.

Next to your new shortcut you will see disabled. Click on that text and then press the key you want to be assigned to your keyboard emulation.

You should now be able to use your search key for pasting!


xbindkeys solution with xdotool

For this solution you will need xbindkeys and xdotool

Kill xbindkeys and dump your button configuration

killall xbindkeys

and

xbindkeys --defaults >> ~/.xbindkeysrc

Add your new bindings

Now you can modify this file to add custom bindings, these have the form

"<command>"
  <key combination>

so if you add

"gedit"
  m:0x0 +b:4

you will open gedit every time you scroll up.

So now you can try one of the following, pick the one that works best for you. In all case xdotool click 2 will be emulated, this is the middle mouse button press, and this will paste both in- and outside terminals.

  1. intercept the 225 from your mouse:

    "xdotool click 2"
      m:0x0 +b:225
    
  2. intercept keycode 225 in general:

    "xdotool click 2"
      c:225
    
  3. replace all XF86Search events (revert your mouse settings to the original settings first, so that you get the XF86Search back):

    "xdotool click 2"
      XF86Search
    

Start xbindkeys and test

Run

xbindkeys

and see if it works.