Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
    
You have xbindkeys set to run when you startup right? Can you disable it and try again? –  Seth Jan 15 '13 at 3:35
    
@iSeth: killed xbindkeys. Tried again, same result. –  Stefano Borini Jan 15 '13 at 11:43
    
Open a terminal and run tail -f /var/log/dmesg then try pressing the button. Do you get any output referring to keys/buttons? –  Seth Jan 16 '13 at 17:06
1  
Before posting another nonsense answer... find out the input id of your mouse with xinput list then find out the button code of your search key with xinput test <MOUSE ID>. Does this work? –  mrcktz Jan 16 '13 at 22:34
1  
There seems to be a confirmed bug that lets xev show the XF86Paste/XF86Copy events, but nothing happens. That means that you have to use the key combination CTRL+v for pasting. Xmodmap maps the buttons 1:1, but you can use the keyboard shortcuts settings to trigger the execution of an command on key press (see my answer). –  mrcktz Jan 17 '13 at 12:33
show 7 more comments

2 Answers

up vote 3 down vote accepted
+100

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!

share|improve this answer
1  
I don't see how this will help on a mouse button, it changes keyboard shortcuts. –  Seth Jan 16 '13 at 21:41
2  
@iSeth: The point is that it turned out that the logitech mouse is both a keyboard and a mouse. It's a mouse for everything except for the search button, where it acts like a keyboard –  Stefano Borini Jan 18 '13 at 8:24
add comment

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.

share|improve this answer
    
I want to let you know that I think you both deserve the bounty as you helped me greatly. I still don't know if your solutions work, I will test them tomorrow, but the bounty is expiring and I don't want it to go to waste. As soon as I have enough points, I will grant you the same bounty. Thanks –  Stefano Borini Jan 20 '13 at 18:25
    
Oke, thanks (although I don't know if that is possible). Glad to be of help ;) –  Gerhard Burger Jan 20 '13 at 19:19
    
uhm... you are right. I can only award one here. Don't worry, As soon as I have enough rep, I'll grant on one of your other answers. –  Stefano Borini Jan 20 '13 at 19:33
    
No,no, don't bother. I'm quite alright ;) –  Gerhard Burger Jan 21 '13 at 8:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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