Volume control using a wheel mouse

I always enjoy listening to music with Volumio.
One thing I miss with Volumio was a hardware volume control like a radio. It is OK to change volume using a mobile phone, but it is much easier if I can change the volume with a knob.
Though there are many articles about changing volume with GPIO switches or encoders, the most familiar knob would be a wheel mouse.

As I am a novice programmer, your comments will be really appreciated.

For your information, I am using Raspberry pi 3B+ with Volumio 2.565 .
An USB DAC and a wheel mouse are connected to my Raspberry pi.


  • Rotate the wheel to change the volume
  • Click the left button to select “Capital UK” (web radio) and the right button to select “Venice classic radio”.


  1. Prepare following “click.js”
    This code is also available at the following site as “index.js” .

var Mouse = require('node-mouse');
var mouseDevice = new Mouse();

var InputEvent = require('input-event');

// find # of mouse event
const execSync = require('child_process').execSync;
const result =  execSync('cat /proc/bus/input/devices | grep mouse0').toString();
n = result.indexOf("event")
var a = result.substring(n+5, n+6)
var input = new InputEvent('/dev/input/event'+a);

var eventDevice = new InputEvent.Mouse(input);

var io=require('socket.io-client');
var socket= io.connect('http://localhost:3000');

// set initial volume value
var vol = 10 ;  
socket.emit('volume', vol);

// Create play lists if empty
socket.on('pushListPlaylist', function(data) {
   if (data.length == 0) {

    socket.emit('createPlaylist',{"name":"Venice Classic Radio"});
	"name":"Venice Classic Radio", 
    socket.emit('createPlaylist',{"name":"Capital FM"});
	"name":"Capital FM", 


var playstate = 1 ;

mouseDevice.on('click', function(e){
  if (e.button === 0) {
//    console.log("left click");
    socket.emit('playPlaylist',{name:"Venice Classic Radio"});
  if (e.button === 2) {
//    console.log("right click");
    socket.emit('playPlaylist',{name:"Capital FM"});
  if (e.button === 1) {
//    console.log("wheel click");
//    socket.emit('prev');
//    socket.emit('next');
  if (playstate == 1) {
	playstate = 0
  else {
	playstate = 1 

// volume setting    
eventDevice.on('wheel', e => {
  var direction = e.value === 1 ? 1 : -1
// get current volume value
 socket.emit('getState', '');
 socket.on('pushState', function(data) {
   vol = data.volume ;  
  vol = vol + direction ;
// volume limitter
  if (vol < 0) vol = 0 ;
  if (vol > 50) vol = 50 ;
  socket.emit('volume', vol);

  1. Login to Volumio and install the following node modules.
sudo su
npm install node-mouse
npm install socket.io-client
npm install input-event
npm install -g forever
  1. Copy “click.js” to
  1. Run
/lib/node_modules/forever/bin/forever start /home/volumio/click.js

If you turn the wheel, the display of Volumio will be linked, and if you click a button, the channel should be switched.

  1. If it is OK, write a node command in /etc/rc.local to run “click.js” automatically at restart.
nano /etc/rc.local

Paste the following before “exit 0”.

/lib/node_modules/forever/bin/forever start /home/volumio/click.js

When you reboot, “click.js” should run.

Due to the recent update of socket.io-client, please install the module as follows:

sudo npm install socket.io-client@2.3.1

1 Like

I wrote a shell script because it is troublesome to copy the files one by one.
The mouse should turn into a volume just by doing the following.

With Raspberry Pi zero, it takes about 3 minutes to install the 4 libraries, so please be patient.

Enable SSH for Volumio, such as http://volumio.local/DEV.

Log in to Volumio using a terminal app.

sudo su
(Enter password, default is volumio)
apt-get update

git clone https://github.com/tullyz/mouse-volume

(note: 'If you get
“fatal: destination path ‘mouse-volume’ already exists and is not an empty directory.” error,
rm -r mouse-volume
and try again. )

cd mouse-volume
chmod u+x setup.sh


When you’re done, insert the mouse and restart.


Adjust the volume with the mouse wheel.
Toggle pause / play when the mouse wheel is pressed.
Left-click to tune in to Venice Classic Radio.
Right-click to tune in Capital London.
Start this software at startup.
The initial volume is 3 and the maximum volume is 50, so if you want to change it, please change the value of /home/volumio/mouse-volume/index.js.

If you want to play with power on, please install AutoStart of Plugins> Miscellanea.
(in case of Volumio2)

How to add AutoAtart feature to Volumio 3 (added 12/12/2021)

  1. First of all, install above-mentioned “mouse-volume” in your raspberry pi.
  2. Then, add socket.emit(‘play’); in ~/mouse-volume/index.js :
// set initial volume value
var vol = 10;
socket.emit('volume', vol);

// auto start
  1. Finally add sleep 30s in /etc/rc.local :
sleep 30s
node /home/volumio/mouse-volume/index.js &

Note) It took 30 seconds for Raspberry Pi 4, but if it is not automatically played on a slow model such as zero, it needs to be longer.

  1. After restarting it, you should be able to play the radio stations or songs in the playlist (Queue) at startup automatically.
1 Like

Works perfect, great job.
Thank you.

Thanks ! Still works, i managed to get this working with a small programmable keyboard.


what keyboard do you use?

Macropad Macro Mechanical Keyboard RGB Mini Gaming Custom Programming Knob Keypads Red Switch 3 Keys For Photoshop

At discount price is like 6euro.
Great add to my player.
Works also with triggerhappy.

great! Do you think or know if it also works with a bluetooth keyboard?

If it has a mouse pad i would guess yes