1

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?

Rafael Muynarsk
  • 2,606
  • 3
  • 18
  • 25
Bas Bakker
  • 13
  • 4

1 Answers1

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:

#!/bin/bash

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
         mousedownFunction
      elif [ ! -z "$(echo "$line" | awk  '/7,5,0,0,1/')" ]; then
         mouseupFunction
      fi  
   done

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.

Rafael Muynarsk
  • 2,606
  • 3
  • 18
  • 25