- Electron Projects
- Denys Vuika
- 300字
- 2021-06-24 12:14:36
Supporting keyboard accelerators
Accelerators are strings that can contain multiple modifiers and a single key code, combined by the + character, and are used to define keyboard shortcuts throughout your application.
Traditionally, menu items in applications provide support for keyboard shortcuts. Nowadays, everyone is used to using the Cmd + S or Ctrl + S combinations to save a file, Cmd + P or Ctrl + P to print a document, and so on.
Electron provides support for keyboard shortcuts, or accelerators, that you can use either globally or with a particular menu item. To create a new keyboard shortcut, you need to add a new attribute called accelerator to your menu item and specify the key combination in plain text.
In the previous examples, when you created a menu item separator, we introduced an additional menu item called Reload. This reloads the embedded browser with each click and allows you to see the updated HTML code. The reload role covers this functionality, but the item has no keyboard shortcut by default. Let's fix this by adding an Alt + R shortcut:
- Edit the menu.js file and add the object, as shown in the following code:
{
role: 'reload',
accelerator: 'Alt+R'
}
- Save the file and restart the application once again.
This time, the Reload menu item has shortcut details listed next to the label. If you are using macOS, for instance, it will be a special Alt symbol, but for Windows and Linux, it may be just the word Alt:

Note that, for many predefined menu roles, the Electron framework provides the most commonly used combinations out of the box.
The next thing we need to address is menus that are specific to a particular platform.
- R語言數(shù)據(jù)分析從入門到精通
- Dynamics 365 Application Development
- Learning Selenium Testing Tools with Python
- Dependency Injection in .NET Core 2.0
- 基于Swift語言的iOS App 商業(yè)實(shí)戰(zhàn)教程
- H5頁面設(shè)計(jì):Mugeda版(微課版)
- Oracle Exadata專家手冊
- Kotlin編程實(shí)戰(zhàn):創(chuàng)建優(yōu)雅、富于表現(xiàn)力和高性能的JVM與Android應(yīng)用程序
- Learning Hadoop 2
- Python 3 數(shù)據(jù)分析與機(jī)器學(xué)習(xí)實(shí)戰(zhàn)
- Instant Zurb Foundation 4
- Mastering Unreal Engine 4.X
- 軟技能2:軟件開發(fā)者職業(yè)生涯指南
- AI輔助編程Python實(shí)戰(zhàn):基于GitHub Copilot和ChatGPT
- Daniel Arbuckle's Mastering Python