> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# On User Command

> Add custom menu items and toolbar buttons with the On User Command event in FlexiCapture, using CI_UserCommand identifiers and sample handler code.

## When it is launched

The event occurs when calling a user command (provided that a corresponding item is added to the main menu or on the toolbar).

User command identifiers can be represented in the form of **CI\_UserCommand** **+ \<non-negative integer>**.

## Parameters

| **Name**  | **Type**                                                         | **Access** | **Description**                    |
| --------- | ---------------------------------------------------------------- | ---------- | ---------------------------------- |
| CommandId | [TCommandID](/flexi-capture/appendix/scripts-shell/tcommandid)   | Read/write | The identifier of the user command |
| Context   | [IMainWindow](/flexi-capture/appendix/scripts-shell/imainwindow) | Read/write | The main window of the application |

<Note>
  To add a user command to the main menu or on the toolbar, you must use **AppendItem / InsertItem** and **AppendButton /InsertButton** methods of the [IMenu](/flexi-capture/appendix/scripts-shell/imenu) interface and the [IToolbar](/flexi-capture/appendix/scripts-shell/itoolbar) interface respectively. The command identifiers **CI\_UserCommand** or **CI\_UserCommand** **+ \<non-negative integer>** must be used.
</Note>

The sample code below demonstrates how to add a menu item for a user command with a command identifier **CI\_UserCommand + 1**.

```
ABBYY.FlexiCapture.ClientUI.TCommandID userCommand = ABBYY.FlexiCapture.ClientUI.TCommandID.CI_UserCommand;
ABBYY.FlexiCapture.ClientUI.TCommandID userCommand1 = (ABBYY.FlexiCapture.ClientUI.TCommandID) ((int)userCommand + 1);
IMenu menu = MainWindow.MainMenu[0].Submenu;
menu.AppendItem( userCommand1, "User command" );
```

A toolbar button or a menu item added for a user command will be disabled unless a handler of the On User Command event is added.

The sample code below demonstrates processing the On User Command event.

```
ABBYY.FlexiCapture.ClientUI.TCommandID commandID = ( ABBYY.FlexiCapture.ClientUI.TCommandID )( CommandId );
ABBYY.FlexiCapture.ClientUI.TCommandID userCommand = ABBYY.FlexiCapture.ClientUI.TCommandID.CI_UserCommand;
ABBYY.FlexiCapture.ClientUI.TCommandID userCommand1 = (ABBYY.FlexiCapture.ClientUI.TCommandID) ((int)userCommand + 1);
if( commandID == userCommand1 ) {
<... call necessary methods here ...>
```
