🚧 VeloxKit is pre-release software. APIs may change before v1.0. Get started →
Documentation
APIs & Bindings
clipboard

clipboard Stable WINMACLNX

Read from and write to the OS system clipboard.

Capability

veloxkit.config.json
{
  "capabilities": ["clipboard"]
}

The TextInput component already handles Ctrl+C / Ctrl+X / Ctrl+V clipboard operations internally. You only need to call clipboard directly for custom copy/paste behavior.

Import

import { clipboard } from 'veloxkit'

clipboard.readText()

Read plain text from the system clipboard.

const text = await clipboard.readText()
// → string (empty string if clipboard is empty or contains non-text)

Returns Promise<string>


clipboard.writeText(text)

Write plain text to the system clipboard. Replaces whatever was on the clipboard.

await clipboard.writeText('Hello, clipboard!')

Returns Promise<void>


Examples

Copy button

function CopyButton({ text }: { text: string }) {
  const [copied, setCopied] = useState(false)
 
  const handleCopy = async () => {
    await clipboard.writeText(text)
    setCopied(true)
    setTimeout(() => setCopied(false), 2000)
  }
 
  return (
    <Pressable
      onPress={handleCopy}
      style={{ padding: '6px 12px', backgroundColor: '#2a2a3e', borderRadius: 6 }}
    >
      <Text style={{ fontSize: 13, color: copied ? '#4ade80' : '#9999cc' }}>
        {copied ? 'Copied!' : 'Copy'}
      </Text>
    </Pressable>
  )
}

Paste from clipboard

<Pressable
  onPress={async () => {
    const pasted = await clipboard.readText()
    if (pasted.trim()) {
      setValue(prev => prev + pasted)
    }
  }}
  style={{ padding: 10, backgroundColor: '#2a2a3e', borderRadius: 6 }}
>
  <Text>Paste</Text>
</Pressable>

Copy rich data as JSON

// Serialize structured data to clipboard as JSON
async function copySelectedRows(rows: Row[]) {
  const json = JSON.stringify(rows, null, 2)
  await clipboard.writeText(json)
}
 
// Paste and parse
async function pasteRows() {
  const text = await clipboard.readText()
  try {
    return JSON.parse(text) as Row[]
  } catch {
    return null  // clipboard didn't contain valid JSON
  }
}