clipboard
cross platform clipboard access in Go
import "golang.design/x/clipboard"
Dependency
- Linux users:
apt install -y libx11-dev
- macOS users: no dependency
Usage
// write texts to the clipboard
clipboard.Write(clipboard.MIMEText, []byte("text data"))
// read texts from the clipboard
clipboard.Read(clipboard.MIMEText)
// write image to the clipboard, assume image bytes are png encoded.
clipboard.Write(clipboard.MIMEImage, []byte("image data"))
// read image from the clipboard
clipboard.Read(clipboard.MIMEImage)
Notes
To put image data to system clipboard, you could:
- On macOS, using shortcut Ctrl+Shift+Cmd+4
- On Linux/Ubuntu, using Ctrl+Shift+PrintScreen
The package supports read/write plain text or PNG encoded image data.
The other types of data are not supported yet, i.e. undefined behavior.
License
GNU GPL-3 Copyright © 2021 The golang.design Initiative Authors, written by Changkun Ou.