Examples

June 6, 2026 · View on GitHub

Runnable examples demonstrating core ScreenCaptureKit APIs.

Quick Start

cargo run --example 01_basic_capture

Examples

#ExampleDescriptionFeatures
01basic_captureSimplest screen capture-
02window_captureCapture specific window-
03audio_captureAudio + video capture-
04pixel_accessRead pixel data from frames-
05screenshotSingle screenshot, HDR capturemacos_14_0, macos_26_0
06iosurfaceZero-copy GPU buffer access-
07list_contentList displays/windows/apps-
08asyncAsync/await API, async pickerasync, macos_14_0
09closure_handlersClosures as handlers-
10recording_outputDirect video recordingmacos_15_0
11content_pickerSystem content picker UImacos_14_0
12stream_updatesDynamic config/filter updates-
13advanced_configHDR, presets, microphonemacos_15_0
14app_captureApplication-based filtering-
15memory_leak_checkMemory leak detection with leaks-
16full_metal_appFull Metal GUI applicationmacos_14_0
17metal_texturesMetal texture creation from IOSurface-
18wgpu_integrationZero-copy wgpu integration-
19ffmpeg_encodingReal-time H.264 encoding via FFmpeg-
20egui_vieweregui screen viewer integration-
21bevy_streamingBevy texture streaming-
22tauri_appTauri 2.0 desktop app with WebGLmacos_14_0
23client_serverClient/server screen sharing-
24batched_apis_showcaseBatched shareable-content APIsmacos_14_0

Running with Features

# Basic examples (no features needed)
cargo run --example 01_basic_capture
cargo run --example 02_window_capture
cargo run --example 12_stream_updates
cargo run --example 14_app_capture

# Async example
cargo run --example 08_async --features async

# Async with picker
cargo run --example 08_async --features "async,macos_14_0"

# macOS 14+ examples
cargo run --example 05_screenshot --features macos_14_0
cargo run --example 11_content_picker --features macos_14_0

# macOS 15+ examples  
cargo run --example 10_recording_output --features macos_15_0
cargo run --example 13_advanced_config --features macos_15_0

# macOS 26+ HDR screenshot
cargo run --example 05_screenshot --features macos_26_0

# Metal GUI example
cargo run --example 16_full_metal_app --features macos_14_0

# Metal textures (no features needed)
cargo run --example 17_metal_textures

# wgpu integration
cargo run --example 18_wgpu_integration

# FFmpeg encoding (requires: brew install ffmpeg)
cargo run --example 19_ffmpeg_encoding

# egui viewer
cargo run --example 20_egui_viewer

# Bevy streaming
cargo run --example 21_bevy_streaming

# Tauri app (separate project, use npm)
cd examples/22_tauri_app && npm install && npm run tauri dev

# Client/server screen sharing
cargo run --example 23_client_server_server  # Terminal 1
cargo run --example 23_client_server_client  # Terminal 2

# All features
cargo run --example 08_async --all-features

Tips

  • Examples are numbered by complexity - start with 01
  • Each example focuses on one API concept
  • Check source code for detailed comments

Full Metal App Example

Example 16 (16_full_metal_app) is a complete macOS application showcasing the full ScreenCaptureKit API:

Features

  • Metal GPU Rendering - Hardware-accelerated graphics with runtime shader compilation
  • Screen Capture - Real-time display/window capture via ScreenCaptureKit
  • Content Picker - System UI for selecting capture source (macOS 14.0+)
  • Audio Visualization - Real-time waveform display with VU meters
  • Screenshot Capture - Single-frame capture with HDR support (macOS 14.0+/26.0+)
  • Video Recording - Direct-to-file recording (macOS 15.0+)
  • Microphone Capture - Audio input with device selection (macOS 15.0+)
  • Bitmap Font Rendering - Custom 8x8 pixel glyph overlay text
  • Interactive Menu - Keyboard-navigable settings UI

Running

# Basic (macOS 14.0+)
cargo run --example 16_full_metal_app --features macos_14_0

# With recording support (macOS 15.0+)
cargo run --example 16_full_metal_app --features macos_15_0

# With HDR screenshots (macOS 26.0+)
cargo run --example 16_full_metal_app --features macos_26_0

Controls

Initial Menu (before picking a source):

  • / - Navigate menu items
  • Enter - Pick Source / Quit

Main Menu (after picking a source - capture auto-starts):

  • / - Navigate menu items
  • Enter - Select item (Stop/Start Capture, Screenshot, Record, Config, Change Source, Quit)
  • Esc/H - Hide menu

Direct Controls (when menu hidden):

  • P - Open content picker
  • Space - Start/stop capture
  • S - Take screenshot
  • R - Start/stop recording (macOS 15.0+)
  • W - Toggle waveform display
  • M - Toggle microphone
  • C - Open config menu
  • H - Show menu
  • Q/Esc - Quit

Data Structure Alignment

The example shows proper Rust/Metal data alignment using #[repr(C)]:

// Rust struct matching Metal shader vertex input
#[repr(C)]
struct Vertex {
    position: [f32; 2],  // 8 bytes - matches packed_float2
    color: [f32; 4],     // 16 bytes - matches packed_float4
}

// Uniforms with explicit padding for 16-byte alignment
#[repr(C)]
struct Uniforms {
    viewport_size: [f32; 2],  // 8 bytes
    time: f32,                // 4 bytes
    _padding: f32,            // 4 bytes (16-byte alignment)
}