Detect and run command upon mouse movement

I am trying to find a way to run a command upon any movement of a mouse.

The 1st statement shows the mouse co-ordinates. So it can detect mouse movement.

xinput test 9

First list input devices:

$ xinput list   

If possible, I would like to use it in a bash script.

If you intend to use xinput then you will need to take a minimum of 2 readings for the mouse......

 xinput query-state <your device name> 

......which will give the results:

2 classes :
ButtonClass
    button[1]=up
    button[2]=up
    button[3]=up
    button[4]=up
    button[5]=up
    button[6]=up
    button[7]=up
ValuatorClass Mode=Relative Proximity=In
    valuator[0]=706
    valuator[1]=570
    valuator[2]=0
    valuator[3]=1560

And the second take:

2 classes :
ButtonClass
    button[1]=up
    button[2]=up
    button[3]=up
    button[4]=up
    button[5]=up
    button[6]=up
    button[7]=up
ValuatorClass Mode=Relative Proximity=In
    valuator[0]=854
    valuator[1]=476
    valuator[2]=0
    valuator[3]=1935

You will then need to compare the two strings for a difference and VOILA you have detected the mouse movement.
As OSX 10.14.1 does NOT have xinput I have once again rebooted to Linux Mint to help.
It is all up to you now to create your bash script to do the task you want.

2 Likes

Thanks again.

My homework is cut out for me. :slight_smile: