LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux 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
 
LinkBack Search this Thread
Old 04-25-2009, 06:03 PM   #1
geekbynature
LQ Newbie
 
Registered: Jul 2008
Location: Colorado
Distribution: Fedora 9
Posts: 20

Rep: Reputation: 0
piping xev to a file to capture mouse clicks


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
 
Old 04-26-2009, 02:51 AM   #2
David the H.
Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 5,314

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
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.
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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


All times are GMT -5. The time now is 09:43 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.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration