Welcome! Log In Create A New Profile


[GUIDE] Adding Physical Buttons to Dockstar to Run Commands

Posted by E4ST2W3ST 
[GUIDE] Adding Physical Buttons to Dockstar to Run Commands
August 29, 2011 09:28PM
***Edit*** Fixed a glitch where moving the mouse while pushing a button caused multiple instances of a command to be run.

Most of you have an extra usb mouse around somewhere. With this python script you can use it to send commands to your dockstar. Simply change the command in the subprocess.Popen() method to use your own.

import subprocess

mouse = file('/dev/input/mouse0')
leftClick = '9'
rightClick = 'a'
middleClick = 'c'
leftRightClick = 'b'
leftRightMidClick = 'f'

state = ''
statusCode = ''

while True:
        status, dx, dy  = tuple(ord(c) for c in mouse.read(3))

        #Get Button Status
        tmp = str(hex(status))
        statusCode =  tmp[-1]

        #Determine what to do on button click
        if statusCode == leftClick:
                if state != leftClick:
                        #Decrease Volume
                        subprocess.Popen('amixer -c 0 set PCM 1dB-', shell=True)
                state = leftClick

        elif statusCode ==  middleClick:
                if state != middleClick:
                        #Next song (pianobar)
                        subprocess.Popen('echo \'n\' > /root/control',shell=True)
                state = middleClick

        elif statusCode == rightClick:
                if state != rightClick:
                        #Increase Volume
                        subprocess.Popen('amixer -c 0 set PCM 1dB+', shell=True)
                state = rightClick

        elif statusCode == leftRightClick:
                if state != leftRightClick:
                        #Do something
                state = leftRightClick

        elif statusCode == leftRightMidClick:
                if state != leftRightMidClick:
                        #Do something else
                        statusCode = null # placeholder ---remove when command is added
                state = leftRightMidClick
                state = ''

        statusCode = ''
* Run in background using this command
nohup python scriptname &


I have been using my Dockstar primarily as a internet radio player and its been a pain to have to login using ssh everytime to change the song, volume, etc...

I have an old optical mouse laying around. Is it possible to remap those mouse buttons to send shell commands such as 'mpc play' 'mpc stop' when these buttons are pushed?

For instance:

Scroll Wheel : Change volume
Middle Button: Play
Left Click: Previous song
Right Click: Next Song

I have a mpd setup for my music as well as pianobar for pandora radio.


Edited 6 time(s). Last edit at 09/06/2011 11:22PM by E4ST2W3ST.
Re: [GUIDE] Adding Physical Buttons to Dockstar to Run Commands
September 03, 2011 01:12AM
Hi there!

Is it possible to obtain the Data for the ScrollWheel of a USB Mouse!

So is it possible to use then the ScrollWheel UP for Volume db+1 and ScrollWheel DOWN for Volume db-1 ?

Thank you for you help in advance

Greetings Ron
Re: [GUIDE] Adding Physical Buttons to Dockstar to Run Commands
September 06, 2011 12:56PM
Unfortunately, I haven't been able to activate the scroll wheel yet. According to this article here the scroll wheel data is not included in the packets sent by the mouse until you send certain commands to the mouse itself. Until I figure out how to send the hex values to the mouse , the commands are limited to button clicks

Your Email:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.