Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Electron Framework, Can I access clipboard?

Tags:

electron

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)

like image 749
Savaratkar Avatar asked Jun 30 '15 05:06

Savaratkar


2 Answers

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.

like image 153
Josh Avatar answered Oct 12 '22 21:10

Josh


const {clipboard} = require('electron')
clipboard.writeText('Example String', 'selection')
console.log(clipboard.readText('selection'))
like image 27
Oded Breiner Avatar answered Oct 12 '22 21:10

Oded Breiner