7

I am new to Electron framework, I wanna know does it have access to native resources like - Clipboard - Keypress (not on my web page, globally. Like a keyboard hook on windows)

dario
  • 5,149
  • 12
  • 28
  • 32
Savaratkar
  • 1,974
  • 1
  • 24
  • 44

2 Answers2

13

I believe what you are looking for is in the clipboard API.

There is also a global shortcut API. Check out this SO answer where I gave an example of how it works.

Here is an example of some basic read/write operations using the clipboard API:

const {clipboard} = require('electron');
clipboard.writeText('Example String');
let clipboardStr = clipboard.readText();

The 'Example String' is the text you would add to the clipboard.

JW.
  • 2,081
  • 1
  • 20
  • 24
Josh
  • 3,225
  • 25
  • 22
2
const {clipboard} = require('electron')
clipboard.writeText('Example String', 'selection')
console.log(clipboard.readText('selection'))
Oded Breiner
  • 28,523
  • 10
  • 105
  • 71
  • Note that this uses the Linux-specific 'selection' clipboard instead of the 'normal' one (that exists on all OSes). Remove 'selection' in the two calls (or replace it with 'clipboard') to use the default clipboard. – JW. Jul 25 '20 at 20:15