Skip to content

xushuosean/clipboard_keyboard

Repository files navigation

clipboard_keyboard

中文文档 | English Doc

Install

npm i --save clipboard_keyboard

Usage

const pasteRef = useRef<ClipboardPaste>();
useEffect(() => {
  pasteRef.current = new ClipboardPaste();
}, [])

useEffect(() => {
  document.addEventListener('keydown', (evt: KeyboardEvent) => {
    if (!(evt.ctrlKey || evt.metaKey)) return
    if (evt.key === 'c') {
      const times = new Date().getTime()
      pasteRef.current?.setCopyValue(times.toString())
    } else if (evt.key === 'v') {
      pasteRef.current?.getPasteValue().then(res => { console.log(res) })
    }
  })
}, [])

API

just three APIs

  • setCopyValue(value: string)
  • getPasteValue(): string
  • dispose(): void remove event listener

Why

As you see,if you want to use the package, you must add event listener to the keydown,and key will be 'c' or 'v'. You can read clipboard by this package

About

a tool for clipboard

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published