> For the complete documentation index, see [llms.txt](https://itrp19-notes.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://itrp19-notes.gitbook.io/notes/reference/python3/code-projects/jiggler-mouse.md).

# Jiggler Mouse

```
import pyautogui
import random
import time
import keyboard

try:
    while True:
        # Check if F11 is pressed to exit
        if keyboard.is_pressed('F11'):
            print("F11 key pressed. Exiting.")
            break

        # Move the mouse cursor randomly
        x_offset = random.randint(-250, 250)
        y_offset = random.randint(-250, 250)
        try:
            pyautogui.moveRel(x_offset, y_offset, duration=0.25)
        except pyautogui.FailSafeException:
            print("Mouse movement failed or reached screen edge. Exiting.")
            break
        time.sleep(0.1)
except ImportError as e:
    print(f"An error occurred: {str(e)}. Please ensure 'pyautogui' and 'keyboard' are installed.")
```
