Skip to main content

Keep your system awake by simulating mouse activity

Project description

pykeepalive

A simple Python tool that keeps your system awake by making tiny periodic mouse movements.

Description

pykeepalive prevents your computer from going to sleep by simulating user activity through small, random mouse movements. It's useful for:

  • Preventing screensaver activation
  • Avoiding system sleep during long-running tasks
  • Keeping remote sessions active
  • Testing scenarios that require system activity

Installation

Prerequisites

  • Python 3.12 or higher
  • uv package manager

Install from source

git clone <repository-url>
cd pykeepalive
uv sync

Usage

Basic Usage

Run the tool to keep your system awake indefinitely:

uv run pykeepalive

The tool will start moving your mouse cursor slightly every 20-60 seconds. Press Ctrl+C to stop.

Command Line Options

  • --min-interval INTEGER: Minimum interval between movements in seconds (default: 20)
  • --max-interval INTEGER: Maximum interval between movements in seconds (default: 60)
  • --duration INTEGER: Run for this many seconds, then stop automatically (useful for testing)

Examples

Run with custom intervals:

uv run pykeepalive --min-interval 10 --max-interval 30

Test for 10 seconds:

uv run pykeepalive --duration 10

How It Works

The tool uses the pynput library to control the mouse cursor. Every random interval (between min and max seconds), it moves the cursor by a small random amount (-2 to +2 pixels in both x and y directions). This tiny movement is usually imperceptible but prevents the system from detecting inactivity.

Testing

To verify the tool is working:

  1. Visual Test: Run uv run pykeepalive --duration 10 and watch your mouse cursor - it should move slightly every few seconds.

  2. Position Check: Use this Python snippet to monitor mouse position:

    from pynput.mouse import Controller
    import time
    
    mouse = Controller()
    print(f"Before: {mouse.position}")
    time.sleep(5)
    print(f"After: {mouse.position}")
    
  3. System Sleep Test: Set your system to sleep after 1-2 minutes, run pykeepalive, and verify the system stays awake.

Requirements

  • pynput>=1.8.1: For mouse control
  • typer>=0.9.0: For command-line interface

License

MIT License

Copyright (c) 2026 vivek

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pykeepalive-0.1.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pykeepalive-0.1.0-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file pykeepalive-0.1.0.tar.gz.

File metadata

  • Download URL: pykeepalive-0.1.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.12

File hashes

Hashes for pykeepalive-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b9e9c8dc5e771e7d919e4d70ff4e4d8f3e150dffdb0a561d514400bb1fd7c0b4
MD5 8dafce1c56e6357d75e4968591b57112
BLAKE2b-256 522d492008a8dd5522010dc5b940e39519d041eb7d6fca3b720d802bba564f15

See more details on using hashes here.

File details

Details for the file pykeepalive-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pykeepalive-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 93b8a7e23049c7ea40230646e1ed1e8de5318d4fa46a76fcc4beb5188691136d
MD5 69723b296351214e5aa8b839f86ccf8d
BLAKE2b-256 c50b79e9f34d045742ffb647853d3cfa910e8842e7d16f3186aa49f988e34ebe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page