Module sfml::window::clipboard

source ·
Expand description

Give access to the system clipboard.

Clipboard provides an interface for getting and setting the contents of the system clipboard.

It is important to note that due to limitations on some operating systems, setting the clipboard contents is only guaranteed to work if there is currently an open window for which events are being handled.

Usage example:

// get the clipboard content as a string
let mut string = clipboard::get_string();
// or use it in the event loop
while let Some(event) = window.poll_event()
{
    match event {
        Event::Closed => window.close(),
        Event::KeyPressed{ctrl, code, ..} => {
            // Using Ctrl + V to paste a string into SFML
            if ctrl && code == Key::V {
                string = clipboard::get_string();
            }
            // Using Ctrl + C to copy a string out of SFML
            if(ctrl && code == Key::C) {
                clipboard::set_string("Hello World!");
            }
        }
        _ => {}
    }
}

Functions

Get the content of the clipboard as string data.
Set the content of the clipboard as string data.