Reputation: 56
I am trying to intercept Ctrl+C and Ctrl+V commands and get the value from the clipboard in Electron. I tried doing it using GlobalShortcut from electron
const ret = globalShortcut.register('CommandOrControl+X', () => {
console.log('CommandOrControl+X is pressed')
})
This is intercepting the keyevent but it stops the original keyevent from happening, One way is to intercept using above code and then manually execute the key event from it. Can anyone please help me with what can be done in this case?
Upvotes: 1
Views: 917
Reputation: 5446
There also is a small library called electron-localshortcut that enables local scope shortcuts in Electron. When the window is inactive, the referenced shortcuts are disabled and given back to Windows' control.
Use like this in your main.js:
const electronLocalshortcut = require('electron-localshortcut');
electronLocalshortcut.register(mainWindow, 'STRG+C', () => {
// Copy to Clipboard
});
Upvotes: 2