clipboard_keyboard
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i clipboard_keyboard

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

244 kB

Total Files

13

Last publish

Collaborators

  • seangary