Global Shortcuts and Clipboard Access
Extend your native OS integration by registering system-wide keyboard shortcuts and reading or writing the system clipboard from Electron.
Global Shortcuts and Clipboard Access is a free Electron Desktop App Development lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Electron Desktop App Development learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Reaching Beyond the Window
Native apps often respond even when not focused. Global shortcuts and clipboard access make your Electron app feel truly native.
The globalShortcut Module
Use globalShortcut in the main process to listen for key combos system-wide, even when your app is in the background.
const { globalShortcut } = require('electron');
app.whenReady().then(() => {
globalShortcut.register('CommandOrControl+Shift+K', () => {
console.log('shortcut fired');
});
});Accelerator Strings
Shortcuts are described with accelerator strings like CommandOrControl+Shift+I, which map correctly across macOS and Windows.
function normalize(accel) {
return accel.replace('CommandOrControl', process.platform === 'darwin' ? 'Cmd' : 'Ctrl');
}
console.log(normalize('CommandOrControl+S'));Checking Registration
Use isRegistered() to avoid conflicts and verify your shortcut actually bound.
if (globalShortcut.isRegistered('CommandOrControl+Shift+K')) {
console.log('active');
}Unregistering Shortcuts
Always clean up on quit with globalShortcut.unregisterAll() in the will-quit event.
app.on('will-quit', () => {
globalShortcut.unregisterAll();
});The clipboard Module
The clipboard module reads and writes text, HTML, and images to the system clipboard.
const { clipboard } = require('electron');
clipboard.writeText('Copied from Electron');
console.log(clipboard.readText());Reading Clipboard Text
clipboard.readText() grabs whatever text the user last copied, enabling paste-aware features.
function preview(text) {
return text.length > 20 ? text.slice(0, 20) + '...' : text;
}
console.log(preview('A very long clipboard string here'));Clipboard Formats
Beyond text, you can read readHTML() and readImage(). Check availableFormats() first.
Combining Both Features
A common pattern: a global shortcut captures the current clipboard text and processes it instantly, like a quick-translate tool.
globalShortcut.register('CommandOrControl+Alt+T', () => {
const text = clipboard.readText();
process(text);
});Respecting the User
Global shortcuts are powerful but intrusive. Make them configurable and avoid hijacking common OS combos.
Security Note
The clipboard may hold sensitive data like passwords. Read it only when the user explicitly triggers an action.
Quick Check
Test your knowledge of global shortcuts.
Recap
You learned to register system-wide shortcuts with globalShortcut, read and write the system clipboard, combine them for native workflows, and handle cleanup and security responsibly.
Frequently asked questions
Is the “Global Shortcuts and Clipboard Access” lesson free?
Yes — the full text of “Global Shortcuts and Clipboard Access” is free to read here on the web, and the Electron Desktop App Development course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Electron Desktop App Development course, upgrade to CoddyKit PRO.
What will I learn in “Global Shortcuts and Clipboard Access”?
Extend your native OS integration by registering system-wide keyboard shortcuts and reading or writing the system clipboard from Electron. You practise Electron Desktop App Development with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Electron Desktop App Development?
No prior experience is required. Electron Desktop App Development on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Global Shortcuts and Clipboard Access” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Electron Desktop App Development lesson?
Yes. Every Electron Desktop App Development lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Native Menus & Context Menus
- Dialogs and Notifications
- Shell Integration
- Global Shortcuts and Clipboard Access