#clipboard #winapi #windows

clipboard-master

Simple utility crate to monitor clipboard changes

11 releases (6 stable)

4.0.0-beta.5 Feb 6, 2024
3.1.3 Nov 23, 2021
3.1.1 Feb 15, 2021
3.0.0 Jun 17, 2019
0.1.0 Mar 17, 2017

#96 in Windows APIs

Download history 233/week @ 2023-12-22 245/week @ 2023-12-29 391/week @ 2024-01-05 163/week @ 2024-01-12 189/week @ 2024-01-19 115/week @ 2024-01-26 80/week @ 2024-02-02 71/week @ 2024-02-09 141/week @ 2024-02-16 191/week @ 2024-02-23 156/week @ 2024-03-01 128/week @ 2024-03-08 112/week @ 2024-03-15 131/week @ 2024-03-22 161/week @ 2024-03-29 137/week @ 2024-04-05

552 downloads per month
Used in 2 crates

MIT license

18KB
307 lines

clipboard-master

Crates.io Docs.rs

Clipboard monitoring library.

Supported platforms

  • Windows - uses dummy window to receive messages when clipboard changes;
  • Linux - uses x11_clipboard
  • MacOS - uses polling via NSPasteboard::changeCount as there is no event notification.

Clipboard Master Library

This project exports Master struct that provides simple way to handle clipboard updates.

Example:

extern crate clipboard_master;

use clipboard_master::{Master, ClipboardHandler, CallbackResult};

use std::io;

struct Handler;

impl ClipboardHandler for Handler {
    fn on_clipboard_change(&mut self) -> CallbackResult {
        println!("Clipboard change happened!");
        CallbackResult::Next
    }

    fn on_clipboard_error(&mut self, error: io::Error) -> CallbackResult {
        eprintln!("Error: {}", error);
        CallbackResult::Next
    }
}

fn main() {
    let mut master = Master::new(Handler).expect("create new monitor");

    let shutdown = master.shutdown_channel();
    std::thread::spawn(move || {
        std::thread::sleep(core::time::Duration::from_secs(1));
        println!("I did some work so time to finish...");
        shutdown.signal();
    });
    //Working until shutdown
    master.run().expect("Success");
}

Dependencies

~0–1.5MB
~29K SLoC