LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux > Linux - General
User Name
Password
Linux - General This forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Thread Tools Search this Thread
Old 04-25-2009, 07:03 PM   #1
geekbynature
LQ Newbie
 
Registered: Jul 2008
Location: Colorado
Distribution: Fedora 9
Posts: 17
Thanked: 0
piping xev to a file to capture mouse clicks


[Log in to get rid of this advertisement]
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
geekbynature is offline     Reply With Quote
Old 04-26-2009, 03:51 AM   #2
David the H.
Senior Member
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian Sid/kde3.5
Posts: 2,684
Thanked: 182
Instead of trying to use xev to detect mouse clicks, I suggest using xbindkeys. You can set it up to sense button clicks and run commands on them. Two lines in the .xbindkeysrc would be all you need. I expect that you'll probably want to run the program in the foreground instead of daemon mode, so you can easily turn it off when you need to use the mouse for regular work.
David the H. is offline     Reply With Quote

Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
xev not showing mouse thumb button number aldar Slackware 4 11-15-2006 03:49 PM
random mouse clicks SuSE 9.3 MichaelLange Linux - Hardware 3 03-09-2006 06:10 PM
How to capture clicks from mouse to a file floydigus Linux - Hardware 2 07-02-2005 02:40 AM
Xorg mouse wheel dead with xev jago25_98 Linux - Software 3 06-05-2005 01:16 AM
Simulated mouse clicks in linux? devilkin Programming 2 02-14-2005 08:59 AM


All times are GMT -5. The time now is 03:36 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Advertisement
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Click Here to receive a complimentary subscription courtesy of LQ.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration