VNC Do Tool (vncdotool)

1.3.0 · active · verified Fri Apr 17

vncdotool is a command-line VNC client that also provides a Python API for programmatic interaction with VNC servers. It enables automation of VNC sessions, including screen capture, sending keystrokes, and executing commands, making it useful for testing, system administration, and CI/CD pipelines. The library is currently at version 1.3.0 and has an active but irregular release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to connect to a VNC server using the `VNCClient` API, capture a screenshot, type some text, and then disconnect. It uses environment variables for host, port, and password for secure credential handling, falling back to common defaults.

import os
from vncdotool.api import VNCClient

# Example: Connect to a VNC server, capture screen, type text, and disconnect

host = os.environ.get('VNC_HOST', 'localhost')
port = int(os.environ.get('VNC_PORT', '5900'))
password = os.environ.get('VNC_PASSWORD', '')

try:
    client = VNCClient(host=host, port=port, password=password)
    print(f"Successfully connected to VNC server at {host}:{port}")

    # Capture a screenshot
    screenshot_path = 'screenshot.png'
    client.captureScreen(screenshot_path)
    print(f"Screenshot saved to {screenshot_path}")

    # Type some text
    client.keyPress('f12') # Example: Press F12
    client.type('Hello, VNC World!')

    # Wait for a brief moment
    client.pause(1000) # Pause for 1 second (1000ms)

except Exception as e:
    print(f"An error occurred: {e}")
finally:
    if 'client' in locals() and client.connected:
        client.disconnect()
        print("Disconnected from VNC server.")

view raw JSON →