Clipboard
Native clipboard.
| Module | require("gui") |
| Type | Object |
The Clipboard class can not be created by user, its instance can only be
recevied by using the factory methods.
// Get the default copy-paste clipboard.
const clipboard = gui.Clipboard.get()
// Changing the content of clipboard with multiple formats of data.
clipboard.setData([
{type: 'text', value: 'some text'},
{type: 'html', value: '<strong>some text</strong>'},
{type: 'image', value: gui.Image.createFromPath('...')},
{type: 'file-paths', value: ['/some/path']},
])
// Read data.
const data = clipboard.getData('text')
if (data.type == 'text')
console.log(data.value)
Class methods
get()
Return the default copy-paste clipboard.
Return
ClipboardfromType(type)
Return the clipboard with type.
Parameters
Clipboard::Typetype
Return
ClipboardMethods
clear()
Clear the clipboard.
setText(text)
Set text as clipboard's content.
Parameters
Stringtext
getText()
Return the content of clipboard as text.
Return
StringisDataAvailable(type)
Return whether the data of type is available.
Parameters
Return
BooleangetData(type)
Get the data of type from clipboard.
You should always check the type of returned data before using it.
Parameters
Return
Clipboard::DatasetData(objects)
Set clipboard's content.
Parameters
Arrayobjects - An array ofClipboard::Data.
startWatching()
Start watching clipboard's content.
The onChange event will be emitted when clipboard's content has
been changed.
On macOS, due to lack of system notifications for clipboard events, this event is implemented by polling every 500ms.
stopWatching()
Stop watching clipboard's content.
Events
onChange(self)
Emitted when clipboard's content has been changed.
The startWatching method must be called first to make this event
work.
Parameters
Clipboardself