m1gin 927
#vlc #vlcplayer #clickandpausevlc #ubuntu #linux #mousebuttons #xinput

To be able to pause/play VLC player by mouse button, I have created a script file. It runs every time the related mouse button clicked. The script check if the active window title contains "VLC media player". If true, then send "space" key.

Script File: control_by_mouse.sh

wintitle=$(xdotool getwindowfocus getwindowname);
p=" - VLC media player$" ;
if [[ $wintitle =~ $p ]]; then
xte 'key space'
fi

xbindkeys needs to be installed to catch and configure mouse events. I edited ~/.xbindkeysrc file and added some codes as follow:

"bash /media/data/test/control_by_mouse.sh"
b:8 #mouse back button

Alternatively there is GUI app for config called xbindkeys-config

After that, the following command should be run

  • xbindkeys

So, every time I press the back button on mouse, the specified script file run.

To get mouse buttons numbers:

  • xev

The folowing packages needed for this work on my Ubuntu system:

sudo apt install xbindkeys xbindkeys-config xautomation xev xdotool


Alternative: xinput

Using xbindkeys, the button missing its functionality in other applications. I couldn't find a way to pass the default event. So I tried a new way using xinput

List available devices and their ids:

  • xinput list

Listen for mouse events (id=10 for me) and pause/play VLC player when mouse button 8 pressed.

I created a script file mouse_events.sh with the following content.

xinput test 10 | while read in ; do
if [[ $in = "button press 8" ]]; then
wintitle=$(xdotool getwindowfocus getwindowname);
p=" - VLC media player$" ;
if [[ $wintitle =~ $p ]]; then
xte 'key space'
echo "captured"
fi
fi
done;

Now we can run the script:

  • bash mouse_events.sh


Resources:

  • https://thecrumb.com/2015/06/03/xbindkeys/index.html
  • https://unix.stackexchange.com/questions/202436/run-program-on-a-key-press-without-interupting-the-key-event
Add to: