2

I know that there are many questions on the internet about setting keyboard/mouse multimedia keys/buttons in Linux, nevertheless my question is more specific.

My wireless input devices:

The above-mentioned keyboard has i.a.:

  • volume up,
  • volume down

keys which work fine. My mouse has few multimedia buttons which don't have assigned any actions. I want to assign to two mouse buttons, the same actions, which are assigned to the volume up/down keyboard keys.

Important note:

When I hold the volume up/down keyboard key down, the volume is gradually getting louder/quieter until volume is maximum/muted. I want the same effect with my mouse.

To fulfill above requirements I followed following steps:

  1. I installed xvkbd, which is virtual keyboard for X window system,
  2. I checked with xev what are the codes of mouse's buttons (8 - volume down, 9 - volume up),
  3. I added following lines to ~/.xbindkeysrc:

    "xvkbd -text '\[XF86AudioLowerVolume]'"
      b:8
    
    "xvkbd -text '\[XF86AudioRaiseVolume]'"
      b:9
    
  4. I brutally 'reloaded' xbindkeys daemon (actually I don't know if it can be called daemon because it starts from /etc/xdg/autostart):

    pkill -f xbindkeys && xbindkeys
    

    BTW: I don't know how to reload it gracefully.

and it almost works. Now I can turn the volume up/down with mouse buttons but if I keep holding volume up/down button, the volume is not getting gradually louder/quieter. It stops after one 'iteration'. I want 'auto-repeat' as long as I'm holding the button down.

Questions:

  • How can I fix it?
  • Is there any other way I can do it? For instance using only xmodmap, instead xvkbd + xbindkeys?

For the sake of completeness:

2

Optimal solution

"xdotool keydown XF86AudioLowerVolume"
b:8

"xdotool keyup XF86AudioLowerVolume"
b:8 + Release

"xdotool keydown XF86AudioRaiseVolume"
b:9

"xdotool keyup XF86AudioRaiseVolume"
b:9 + Release

This will behave as the keyboard keys as it will continue changing up/down the volume until you release the mouse button.

Happy coding...

1
$ sudo apt-get install xdotool
$ sudo apt-get install xbindkeys
$ vim ~/.xbindkeysrc

Contents:

# Sound Lower
"xdotool key XF86AudioLowerVolume"
  b:8

# Sound Louder
"xdotool key XF86AudioRaiseVolume"
  b:9

Save and close.

$ xbindkeys

This works for me. Logitech M500 on Ubuntu 14.04.

0

Some logitech mice have programmable buttons. Some of those have onboard storage to make profiles stored on the mouse. If you have access to a computer that can run Logitech's mouse setup software, you could make the mouse's USB keyboard component send multimedia-key presses (I think with autorepeat), instead of handling it in software on the GNU/Linux side.

For example, my G602 sends an F6 keypress when I press one of its buttons, even when I have it connected to my Linux desktop. Mice without onboard profile storage will only be able to have their buttons remapped by software (e.g. what you did, or Logitech's own software running under Windows).

IDK how to set up autorepeat for mouse buttons mapped to keyboard keys as you've done.

  • Very unclear answer for me. I mentioned which model of Logitech mouse I own. I don't understand how setting up some mouse's profile (what is mouse's profile?) on different system can help. This mouse works fine (ie. as I want to work on Linux) on Windows 8.1 out of the box. I want solution for Linux. You can assume that I have only Linux Debian. – patryk.beza Aug 11 '15 at 20:15
  • @patryk.beza: I edited an explanation into my answer. I used to have a Windows gaming machine around, and I used that to set up the buttons on a mouse that I now use with GNU/Linux. I know this isn't a very good answer, since it assumes access to a Windows PC. This might work from a VM if you give it direct access to a USB port. (and have a copy of windows you can run in the VM) – Peter Cordes Aug 11 '15 at 20:33
0

If you want the mouse buttons to act the same as the multimedia buttons on a keyboard, you have to emulate the keydown and keyup events as opposed to a one-shot keypress. Here's a quick script I use to set this up on my systems:

sudo apt install xdotool xbindkeys

echo "Setting up ~/.xbindkeysrc"
cat <<EOF >> ~/.xbindkeysrc
# Sound Lower
"xdotool keydown XF86AudioLowerVolume"
  b:8
"xdotool keyup XF86AudioLowerVolume"
  b:8 + release

# Sound Louder
"xdotool keydown XF86AudioRaiseVolume"
  b:9
"xdotool keyup XF86AudioRaiseVolume"
  b:9 + release
EOF

echo "Running xbindkeys"
xbindkeys

~

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.