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

Install from PyPI

pip install pykeepalive

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.1.tar.gz (9.9 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.1-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pykeepalive-0.1.1.tar.gz
Algorithm Hash digest
SHA256 69c24d59be0b2ea9a34b6b874bfc1acb4a9f14849c59e9bf1f82e86709ef306a
MD5 2a226ff4d8e180159c8a345bda7a0a54
BLAKE2b-256 b7132cf876f8e8ac7886d9ba2b9793eec1e89e0dd327fe6e4aaca5630236f562

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pykeepalive-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e8da246691c175eb5b76cf10f11a66206ca5da254a696fb8f9f19c35fd682fc9
MD5 e3a732ee664f5fb949edf1d86008dbc8
BLAKE2b-256 009ac9a4036408680eb9af2cd16d819f819c357c4cb014ac1150eeac733cb24b

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