SFML 3.0.2
Loading...
Searching...
No Matches
Functions
sf::Clipboard Namespace Reference
Window module

Give access to the system clipboard. More...

## Functions
String | getString ()
| Get the content of the clipboard as string data.
void | setString (const String &text)
| Set the content of the clipboard as string data.

## Detailed Description

Give access to the system clipboard.

sf::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
sf::String string = sf::Clipboard::getString();
// or use it in the event loop
while (const std::optional event = window.pollEvent())
{
if (event->is<sf::Event::Closed>())
window.close();
if (const auto* keyPressed = event->getIf<sf::Event::KeyPressed>())
{
// Using Ctrl + V to paste a string into SFML
if (keyPressed->control && keyPressed->code == sf::Keyboard::Key::V)
string = sf::Clipboard::getString();
// Using Ctrl + C to copy a string out of SFML
if (keyPressed->control && keyPressed->code == sf::Keyboard::Key::C)
sf::Clipboard::setString("Hello World!");
}
}
sf::String
Utility string class that automatically handles conversions between types and encodings.
Definition String.hpp:89
sf::Clipboard::setString
void setString(const String &text)
Set the content of the clipboard as string data.
sf::Clipboard::getString
String getString()
Get the content of the clipboard as string data.
sf::Keyboard::Key::C
@ C
The C key.
Definition Keyboard.hpp:56
sf::Keyboard::Key::V
@ V
The V key.
Definition Keyboard.hpp:75
sf::Event::Closed
Closed event subtype.
Definition Event.hpp:55
sf::Event::KeyPressed
Key pressed event subtype.
Definition Event.hpp:97

See also
  sf::String, sf::Event

## Function Documentation

## ◆ getString()

String sf::Clipboard::getString | ( |  | ) |
| nodiscard

Get the content of the clipboard as string data.

This function returns the content of the clipboard as a string. If the clipboard does not contain string it returns an empty sf::String object.

Returns
  Clipboard contents as sf::String object

## ◆ setString()

void sf::Clipboard::setString | ( | const String & | text | ) |

Set the content of the clipboard as string data.

This function sets the content of the clipboard as a string.

Warning
  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.

Parameters

  text | sf::String containing the data to be sent to the clipboard