I have a USB mouse with two buttons. As all my music is on my laptop, I sometimes like to put it under the seat of my car and connect one of those audio jacks with a cassette on the other end, so it will send the audio to my car speakers. This works great, except that I can't skip songs.
So I attached the USB mouse to my dashboard and wrote a simplistic (read: hurriedly written in 5 minutes!) bash script that works with xev to determine when a button is pressed. If there's a left click, it goes to the previous song. If there's a right click, it skips to the next. It works great, but my question is this:
After I click, I always have to jiggle the mouse before the click is actually written to the file; if the cursor doesn't move, the script won't work. This is annoying. How can I get it so that all I do is click, and not have to move anything? Is there a better way to pipe the xev output to a file other than cat? I tree using tee, but that didn't work at all.
I'm using the command 'xev | cat >> CLICKS' to write to the file, and here's the bash script:
Code:
#!/bin/bash
DONE=NO
aa=`grep 'button 1' CLICKS | wc -l | awk '{print$1}'`
ab=`grep 'button 3' CLICKS | wc -l | awk '{print$1}'`
while [ $DONE = NO ] ; do
bb=`grep 'button 1' CLICKS | wc -l | awk '{print$1}'`
bc=`grep 'button 3' CLICKS | wc -l | awk '{print$1}'`
if [ $bb -gt $aa ] ; then
echo "Button 1 was pressed"
xmms -r
aa=$bb
elif [ $bc -gt $ab ] ; then
echo "Button 2 was pressed"
xmms -f
ab=$bc
fi
done