# CommandEvent

This event type is fired when the program is about to carry out a "command" - a specific program function. The user can initiate commands by selecting items from menus, pressing buttons mapped to commands, or by mouse selections (e.g., selecting from a right-click context menu). See Commands for a list of the command functions.

The event target for this event type is the mainWindow object.

The CommandEvent class has only one subtype:

- command: Fires when a user action triggers a system command.

As with most event types, a CommandEvent fires before the system carries out its normal handling for the command. This allows you to block a command entirely by calling preventDefault() on the event object in your handler. For example, if you wanted to prevent the user from being able to exit out of PinballY using the menus, you could do something like this:

mainWindow.on("command", ev => { if (ev.id == command.Quit) ev.preventDefault(); });

## Properties

- id: The integer identifier of the command. You can compare this to the identifiers defined as properties of the command object.
- index: If the command is part of a ranged group (such as command.FilterFirst ... command.FilterLast), this will contain an integer giving the index of the command within the group, starting at 0 for the first command of the group. For a command that isn't part of a range group, the index property isn't present (so it will return undefined if read, per normal Javascript rules).
- name: A string giving the name of the command. The command names are the same as the property names of the command object. For "ranged" commands (such as command.FilterFirst ... command.FilterLast), the name is always the name of the first command of the range, such as command.FilterFirst, and the .index property is set to the index of the command within the range group. For example, if event.id == command.FilterFirst + 10, event.name will contain "FilterFirst", and event.index will be set to 10. The index is set to zero when the command is the first command of a range group.