#Windows #winapi #clipboard

clipboard-win

Provides simple way to interact with Windows clipboard

51 releases (32 stable)

4.0.2 Jul 21, 2020
4.0.0-beta.1 Jun 26, 2020
3.1.1 Jun 25, 2020
3.0.1 Feb 22, 2020
0.9.3 Jul 16, 2015

#2 in Windows APIs

Download history 3213/week @ 2020-04-20 3379/week @ 2020-04-27 3291/week @ 2020-05-04 2831/week @ 2020-05-11 2706/week @ 2020-05-18 3430/week @ 2020-05-25 3198/week @ 2020-06-01 4088/week @ 2020-06-08 4018/week @ 2020-06-15 4511/week @ 2020-06-22 4802/week @ 2020-06-29 4230/week @ 2020-07-06 4990/week @ 2020-07-13 4510/week @ 2020-07-20 4995/week @ 2020-07-27 3729/week @ 2020-08-03

16,112 downloads per month
Used in 134 crates (9 directly)

BSL-1.0 license

45KB
739 lines

clipboard-win

Build Crates.io Docs.rs

This crate provide simple means to operate with Windows clipboard.

Note keeping Clipboard around:

In Windows Clipboard opens globally and only one application can set data onto format at the time.

Therefore as soon as operations are finished, user is advised to close Clipboard.

Clipboard

All read and write access to Windows clipboard requires user to open it.

Usage

Manually lock clipboard

use clipboard_win::{Clipboard, formats, Getter, Setter};

const SAMPLE: &str = "MY loli sample ^^";

let _clip = Clipboard::new_attempts(10).expect("Open clipboard");
formats::Unicode.write_clipboard(&SAMPLE).expect("Write sample");

let mut output = String::new();

assert_eq!(formats::Unicode.read_clipboard(&mut output).expect("Read sample"), SAMPLE.len());
assert_eq!(output, SAMPLE);

//Efficiently re-use buffer ;)
output.clear();
assert_eq!(formats::Unicode.read_clipboard(&mut output).expect("Read sample"), SAMPLE.len());
assert_eq!(output, SAMPLE);

//Or take the same string twice?
assert_eq!(formats::Unicode.read_clipboard(&mut output).expect("Read sample"), SAMPLE.len());
assert_eq!(format!("{0}{0}", SAMPLE), output);

Simplified API

use clipboard_win::{formats, get_clipboard, set_clipboard};

let text = "my sample ><";

set_clipboard(formats::Unicode, text).expect("To set clipboard");
//Type is necessary as string can be stored in various storages
let result: String = get_clipboard(formats::Unicode).expect("To set clipboard");
assert_eq!(result, text)

Dependencies

~77KB