Adding Keyboard Shortcuts to your Equo Application

You can configure shortcuts in your application by using the Java or the Javascript API. Both APIs are able to detect keyboard events and perform user actions.

In an Equo application, shortcuts are linked to Menu items. That means that when configured they are attached to these UI components.

Adding shortcuts using the Javascript API

To configure a shortcut in your application, you have to specify a key sequence in the addShortcut method of a Menu:

import { Menu } from "@equo/equo-application-menu";

this.menuWithoutEditor = Menu.create()
  .withMainMenu("File")
  .addMenuItem("Open folder")
    .addShortcut("M1+O")
    .onClick(console.log("Your Equo app is awesome!"))
      .addMenuItem("Exit")
        .addShortcut("M1+Q")
        .onClick("exitapphandler");

this.menuWithoutEditor.setApplicationMenu();

Note how you can also send events when configuring a shortcut: the exitapphandler event will be triggered when the last shortcut is pressed. The parameter M1+Q is a key sequence. Please see below the key sequences section for more information.

After launching your Equo app, you will see the application menus along with the shortcuts you just defined.

Adding shortcuts using the Java API

You can use the EquoApplicationBuilder class to add shortcuts to your application. See the following lines:

appBuilder
  .withUI("/")
  .withMainMenu("File")
  .addMenuItem("New")
     .onClick(() -> System.out.println("menuitem event"))
     .addShortcut("M1+I");

Key sequences

In an Equo application, shortcuts are defined by key sequences. A key sequence consist of one or more key strokes. Key strokes consist of one or more keys held down at the same time. This should be zero or more modifier keys, and one other key. The keys are separated by the + character.

Equo recognizes the modifiers M1, M2, M3, and M4. The "M" modifier key is a platform-independent way of representing keys. Review the table below to understand what the "M" modifier represents in each platform:

Modifier Key macOS Other platforms

M1

COMMAND

CTRL

M2

SHIFT

SHIFT

M3

OPTION

ALT

M4

CTRL

Undefined

The actual key is generally specified simply in uppercase. For example F or J, are examples of such keys.