I want the system to listen for a button press and then a mouse Right/left/up/down movement. I know which button is pressed by XEV, but I don’t know how to listen for mouse movements and then execute something. Does anyone know how can I do it?

1 Answer 1


Considering that you're using Xorg as the default X Window server you can accomplish it installing cnee. A simple bash script that can read the actions of left-clicking the mouse would be:


mousedownFunction () {
   echo "mouse down event"

mouseupFunction () {
   echo "mouse up event"

cnee --record --mouse |
   while read line; do
      if [ ! -z "$(echo "$line" | awk  '/7,4,0,0,1/')"  ]; then
      elif [ ! -z "$(echo "$line" | awk  '/7,5,0,0,1/')" ]; then

The result is:

enter image description here

OBS: When you run the command cnee --record --mouse on a terminal window you'll see that it categorizes each mouse action with a specific number. On the script's example 7,4,0,0,1 represents left-click mousedown and 7,5,0,0,1 represents left-click mouseup. But you can capture other actions as well, as middle click, right click, mouse up/down scrolls and mouse movements. You just need to adapt the script to suit your needs.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .