الاختصارات العامة والوصول إلى الحافظة
وسّع تكامل تطبيقك مع نظام التشغيل الأصلي عبر تسجيل اختصارات لوحة مفاتيح على مستوى النظام، وقراءة حافظة النظام أو الكتابة فيها من Electron.
الاختصارات العامة والوصول إلى الحافظة درس مجاني في Electron Desktop App Development على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Electron Desktop App Development، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Electron Desktop App Development 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
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.
تعلم JavaScript مع معلم ذكاء اصطناعي — مجانًا
اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.
- الدورات
- 12
- الدروس
- 47
الأسئلة الشائعة
هل درس «الاختصارات العامة والوصول إلى الحافظة» مجاني؟
نعم — نص درس «الاختصارات العامة والوصول إلى الحافظة» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Electron Desktop App Development، انتقل إلى CoddyKit PRO. تتضمن دورة Electron Desktop App Development 4 دروس في المجموع.
ماذا ستتعلم في «الاختصارات العامة والوصول إلى الحافظة»؟
وسّع تكامل تطبيقك مع نظام التشغيل الأصلي عبر تسجيل اختصارات لوحة مفاتيح على مستوى النظام، وقراءة حافظة النظام أو الكتابة فيها من Electron. تتمرن على Electron Desktop App Development مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Electron Desktop App Development؟
لا تُشترط خبرة سابقة. Electron Desktop App Development على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «الاختصارات العامة والوصول إلى الحافظة»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Electron Desktop App Development هذا؟
نعم. كل درس في Electron Desktop App Development يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- القوائم الأصلية وقوائم السياق
- مربعات الحوار والإشعارات
- التكامل مع الصدفة
- الاختصارات العامة والوصول إلى الحافظة