Skip to content

Instantly share code, notes, and snippets.

@atwalsh
Last active March 1, 2023 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atwalsh/9ee946983e35cec246b3897ece1c9192 to your computer and use it in GitHub Desktop.
Save atwalsh/9ee946983e35cec246b3897ece1c9192 to your computer and use it in GitHub Desktop.
Move mouse on Raspberry Pi
#!/bin/bash
# Credit: https://fitzcarraldoblog.wordpress.com/2018/08/06/how-to-move-a-mouse-pointer-automatically-in-linux-to-simulate-user-activity/
# Script to keep mouse pointer moving so that, for example, Suspend to RAM timeout does not occur.
#
# The mouse pointer will move around its current position on the screen, i.e. around any position
# on the screen where you place the pointer. However, if you prefer it to move around the centre
# of the screen then change mousemove_relative to mousemove in the xdotool command below.
#
# Set LENGTH to 0 if you do not want the mouse pointer to actually move.
# Set LENGTH to 1 if you want the mouse pointer to move just a tiny fraction.
# Set LENGTH to e.g. 100 if you want to see more easily the mouse pointer move.
export DISPLAY=:0
LENGTH=5
#
# Set DELAY to the desired number of seconds between each move of the mouse pointer.
DELAY=5
#
for ANGLE in 0 90 180 270
do
xdotool mousemove_relative --polar $ANGLE $LENGTH
sleep $DELAY
done
  • Create mouse.sh in /home/raspberrypi/mouse.sh

  • Edit crontab

    • crontab -e
    • Add * * * * * bash /home/raspberrypi/mouse.sh

    Install xdotool:

    sudo apt-get install xdotool
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment