Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect mouse click in bash script

Tags:

bash

unix

mouse

I'm wondering how to run a bash script in the background that will do something (i.e. run a script, or a command, or whatever) whenever a user clicks the mouse. I'd like this to continue running even if the terminal is closed. Any ideas? Thanks!

like image 941
Mason Avatar asked Dec 02 '11 19:12

Mason


2 Answers

If you are using X11, you can try xdotool to catch mouse events

It would be something like:

xdotool search --onlyvisible . behave %@ mouse-click getmouselocation

xdotool manual

If you want to run the script in background you can use:

./myscript.sh &>/dev/null &
like image 152
Alessandro Pezzato Avatar answered Sep 22 '22 07:09

Alessandro Pezzato


if you just want to run bash command in xterm on mouse click (or wheel event) you can try this example:

$ echo -e "\e[?1000h"

$ while read -n 6; do echo hellowworld; done

this is for wheel event (for click set 12 instead)

like image 34
Ivan M Avatar answered Sep 22 '22 07:09

Ivan M