mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-10-01 03:11:45 +00:00
implement Demo App sections: Dialogs, Menu, Tray, Shell, CrashHang, Notification, Shortcuts etc. Fix some API bugs and implement GlobalShortcut-, Shell- and WebContents-API.
This commit is contained in:
74
ElectronNET.WebApp/Views/Shortcuts/Index.cshtml
Normal file
74
ElectronNET.WebApp/Views/Shortcuts/Index.cshtml
Normal file
@@ -0,0 +1,74 @@
|
||||
<template class="task-template">
|
||||
<section id="shortcuts-section" class="section js-section u-category-menu">
|
||||
<header class="section-header">
|
||||
<div class="section-wrapper">
|
||||
<h1>
|
||||
<svg class="section-icon"><use xlink:href="assets/img/icons.svg#icon-menu"></use></svg>
|
||||
Keyboard Shortcuts
|
||||
</h1>
|
||||
|
||||
<h3>The <code>Electron.GlobalShortcut</code> and <code>MenuItem</code> can be used to define keyboard shortcuts.</h3>
|
||||
|
||||
<p>
|
||||
In Electron.NET, keyboard shortcuts are called accelerators.
|
||||
They can be assigned to actions in your application's Menu,
|
||||
or they can be assigned globally so they'll be triggered even when
|
||||
your app doesn't have keyboard focus.
|
||||
</p>
|
||||
|
||||
<p>You find the sample source code in <code>Controllers\ShortcutsController.cs</code>.</p>
|
||||
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="demo">
|
||||
<div class="demo-wrapper">
|
||||
<button id="shortcuts-demo-toggle" class="js-container-target demo-toggle-button">Register a global keyboard shortcut
|
||||
<div class="demo-meta u-avoid-clicks">Supports: Win, macOS, Linux <span class="demo-meta-divider">|</span> Process: Main</div>
|
||||
</button>
|
||||
<div class="demo-box">
|
||||
<p>
|
||||
To try this demo, press <kbd class="normalize-to-platform">CommandOrControl+Alt+K</kbd> on your keyboard.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Global shortcuts are detected even when the app doesn't have
|
||||
keyboard focus.
|
||||
</p>
|
||||
|
||||
<h5>Main Process</h5>
|
||||
<pre><code class="csharp">Electron.GlobalShortcut.Register("CommandOrControl+Alt+K", async () => {
|
||||
var options = new MessageBoxOptions("You pressed the registered global shortcut keybinding.")
|
||||
{
|
||||
Type = MessageBoxType.info,
|
||||
Title = "Success!"
|
||||
};
|
||||
|
||||
await Electron.Dialog.ShowMessageBoxAsync(options);
|
||||
});
|
||||
|
||||
Electron.App.WillQuit += () => Electron.GlobalShortcut.UnregisterAll();</code></pre>
|
||||
|
||||
<div class="demo-protip">
|
||||
<h2>ProTip</h2>
|
||||
<strong>Avoid overriding system-wide keyboard shortcuts.</strong>
|
||||
<p>
|
||||
When registering global shortcuts, it's important to be aware of
|
||||
existing defaults in the target operating system, so as not to
|
||||
override any existing behaviors. For an overview of each
|
||||
operating system's keyboard shortcuts, view these documents:
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li><a class="u-exlink" href="https://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/OSXHIGuidelines/Keyboard.html">macOS</a></li>
|
||||
<li><a class="u-exlink" href="http://windows.microsoft.com/en-us/windows-10/keyboard-shortcuts">Windows</a></li>
|
||||
<li><a class="u-exlink" href="https://developer.gnome.org/hig/stable/keyboard-input.html.en">Linux</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</section>
|
||||
</template>
|
||||
Reference in New Issue
Block a user