[GUIDE] Adding Physical Buttons to Dockstar to Run Commands August 29, 2011 09:28PM |
Registered: 13 years ago Posts: 3 |
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 subprocess.Popen('pianobar',shell=True) state = leftRightClick elif statusCode == leftRightMidClick: if state != leftRightMidClick: #Do something else #subprocess.Popen('',shell=True) statusCode = null # placeholder ---remove when command is added state = leftRightMidClick else: state = '' statusCode = ''* Run in background using this command
nohup python scriptname &
Quote
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.
Thanks!
Re: [GUIDE] Adding Physical Buttons to Dockstar to Run Commands September 03, 2011 01:12AM |
Registered: 14 years ago Posts: 23 |
Re: [GUIDE] Adding Physical Buttons to Dockstar to Run Commands September 06, 2011 12:56PM |
Registered: 13 years ago Posts: 3 |