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)
Asked
Active
Viewed 8,347 times
2 Answers
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.
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