SFML 2.5.1

- Main Page
- Related Pages
- Topics
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Static Public Member Functions | List of all members
sf::Clipboard Class Reference
Window module

Give access to the system clipboard. More...

`#include <Clipboard.hpp>`

## Static Public Member Functions

static String | getString ()
| Get the content of the clipboard as string data.
static 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
sf::Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
window.close();
if(event.type == sf::Event::KeyPressed)
{
// Using Ctrl + V to paste a string into SFML
if(event.key.control && event.key.code == sf::Keyboard::V)
string = sf::Clipboard::getString();
// Using Ctrl + C to copy a string out of SFML
if(event.key.control && event.key.code == sf::Keyboard::C)
sf::Clipboard::setString("Hello World!");
}
}
sf::Clipboard::setString
static void setString(const String &text)
Set the content of the clipboard as string data.
sf::Clipboard::getString
static String getString()
Get the content of the clipboard as string data.
sf::Event
Defines a system event and its parameters.
Definition Event.hpp:45
sf::Event::key
KeyEvent key
Key event parameters (Event::KeyPressed, Event::KeyReleased)
Definition Event.hpp:224
sf::Event::type
EventType type
Type of the event.
Definition Event.hpp:219
sf::Event::Closed
@ Closed
The window requested to be closed (no data)
Definition Event.hpp:189
sf::Event::KeyPressed
@ KeyPressed
A key was pressed (data in event.key)
Definition Event.hpp:194
sf::Keyboard::C
@ C
The C key.
Definition Keyboard.hpp:53
sf::Keyboard::V
@ V
The V key.
Definition Keyboard.hpp:72
sf::String
Utility string class that automatically handles conversions between types and encodings.
Definition String.hpp:46
sf::Event::KeyEvent::code
Keyboard::Key code
Code of the key that has been pressed.
Definition Event.hpp:64
sf::Event::KeyEvent::control
bool control
Is the Control key pressed?
Definition Event.hpp:66

See also
  sf::String, sf::Event

Definition at line 41 of file Clipboard.hpp.

## Member Function Documentation

## ◆ getString()

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

static

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()

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

static

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

The documentation for this class was generated from the following file:

- Clipboard.hpp