https://github.com/dacap/clip
  
  
    Cross-platform C++ library to copy/paste clipboard content 
    https://github.com/dacap/clip
  
clipboard clipboard-formats cpp linux macos nspasteboard pasteboard windows x11
        Last synced: 6 months ago 
        JSON representation
    
Cross-platform C++ library to copy/paste clipboard content
- Host: GitHub
 - URL: https://github.com/dacap/clip
 - Owner: dacap
 - License: mit
 - Created: 2015-07-28T23:18:51.000Z (over 10 years ago)
 - Default Branch: main
 - Last Pushed: 2025-04-01T11:54:21.000Z (7 months ago)
 - Last Synced: 2025-04-07T04:08:37.697Z (7 months ago)
 - Topics: clipboard, clipboard-formats, cpp, linux, macos, nspasteboard, pasteboard, windows, x11
 - Language: C++
 - Homepage:
 - Size: 158 KB
 - Stars: 648
 - Watchers: 17
 - Forks: 93
 - Open Issues: 15
 - 
            Metadata Files:
            
- Readme: README.md
 - Contributing: CONTRIBUTING.md
 - License: LICENSE.txt
 
 
Awesome Lists containing this project
- AwesomeCppGameDev - clip - platform C++ library to copy/paste clipboard content (C++)
 
README
          # Clip Library
*Copyright (c) 2015-2024 David Capello*
[](https://github.com/dacap/clip/actions?query=workflow%3Abuild)
[](LICENSE.txt)
Library to copy/retrieve content to/from the clipboard/pasteboard.
## Features
Available features on Windows, macOS, and Linux (X11):
* Copy/paste UTF-8 text.
* Copy/paste user-defined data.
* Copy/paste RGB/RGBA images. This library use non-premultiplied alpha RGB values.
## Example
```cpp
#include "clip.h"
#include 
int main() {
  clip::set_text("Hello World");
  std::string value;
  clip::get_text(value);
  std::cout << value << "\n";
}
```
## User-defined clipboard formats
```cpp
#include "clip.h"
int main() {
  clip::format my_format =
    clip::register_format("com.appname.FormatName");
  int value = 32;
  std::string str = "Alternative text for value 32";
  clip::lock l;
  l.clear();
  l.set_data(clip::text_format(), str.c_str(), str.size());
  l.set_data(my_format, (const char*)&value, sizeof(int));
}
```
## Platform specific details
* If two versions of your application (32-bit and 64-bit) can run at
  at the same time, remember to avoid storing data types that could
  change depending on the platform (e.g. `size_t`) in your custom
  format data.
* **Windows**:
  - [Limited number of clipboard formats on Windows](https://web.archive.org/web/20250126161802/https://devblogs.microsoft.com/oldnewthing/20080430-00/?p=22523)
* **Linux**:
  - To be able to copy/paste on Linux you need `libx11-dev`/`libX11-devel` package.
  - To copy/paste images you will need `libpng-dev`/`libpng-devel` package.
## Compilation Flags
* `CLIP_ENABLE_IMAGE`: Enables the support to
  [copy](examples/put_image.cpp)/[paste](examples/show_image.cpp) images.
* `CLIP_ENABLE_LIST_FORMATS` (only for Windows): Enables the
  `clip::lock::list_formats()` API function and the
  [list_clip_formats](examples/list_clip_formats.cpp) example.
* `CLIP_EXAMPLES`: Compile [examples](examples/).
* `CLIP_TESTS`: Compile [tests](tests/).
* `CLIP_INSTALL`: Generate installation rules for CMake.
* `CLIP_X11_WITH_PNG` (only for Linux/X11): Enables support to
  copy/paste images using the `libpng` library on Linux.
## Who is using this library?
[Check the wiki](https://github.com/dacap/clip/wiki#who-is-using-clip)
to know what projects are using the `clip` library.