> ## Documentation Index
> Fetch the complete documentation index at: https://dripart-docs-recommend-assets-api.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# コマンドとキーバインディング

コマンドとキーバインディング API により、拡張機能はカスタムコマンドを登録し、キーボードショートカットに関連付けることができます。これにより、ユーザーはマウスを使用せずにアクションを迅速にトリガーできます。

## 基本的な使い方

```javascript theme={null}
app.registerExtension({
  name: "MyExtension",
  // コマンドの登録
  commands: [
    {
      id: "myCommand",
      label: "マイコマンド",
      function: () => {
        console.log("コマンドが実行されました！");
      }
    }
  ],
  // コマンドにキーバインディングを関連付け
  keybindings: [
    {
      combo: { key: "k", ctrl: true },
      commandId: "myCommand"
    }
  ]
});
```

## コマンド設定

各コマンドには `id`、`label`、`function` が必要です：

```javascript theme={null}
{
  id: string,              // コマンドの一意な識別子
  label: string,           // コマンドの表示名
  function: () => void     // コマンドがトリガーされたときに実行される関数
}
```

## キーバインディング設定

各キーバインディングには `combo` と `commandId` が必要です：

```javascript theme={null}
{
  combo: {                 // キーの組み合わせ
    key: string,           // メインキー（単一文字または特殊キー）
    ctrl?: boolean,        // Ctrl キーが必要（オプション）
    shift?: boolean,       // Shift キーが必要（オプション）
    alt?: boolean,         // Alt キーが必要（オプション）
    meta?: boolean         // Meta/Command キーが必要（オプション）
  },
  commandId: string        // トリガーするコマンドの ID
}
```

### 特殊キー

非文字キーの場合は、以下の値のいずれかを使用してください：

* 矢印キー：`"ArrowUp"`、`"ArrowDown"`、`"ArrowLeft"`、`"ArrowRight"`
* 機能キー：`"F1"` から `"F12"`
* その他の特殊キー：`"Escape"`、`"Tab"`、`"Enter"`、`"Backspace"`、`"Delete"`、`"Home"`、`"End"`、`"PageUp"`、`"PageDown"`

## コマンド例

```javascript theme={null}
app.registerExtension({
  name: "CommandExamples",
  commands: [
    {
      id: "runWorkflow",
      label: "ワークフローを実行",
      function: () => {
        app.queuePrompt();
      }
    },
    {
      id: "clearWorkflow",
      label: "ワークフローをクリア",
      function: () => {
        if (confirm("ワークフローをクリアしますか？")) {
          app.graph.clear();
        }
      }
    },
    {
      id: "saveWorkflow",
      label: "ワークフローを保存",
      function: () => {
        app.graphToPrompt().then(workflow => {
          const blob = new Blob([JSON.stringify(workflow)], {type: "application/json"});
          const url = URL.createObjectURL(blob);
          const a = document.createElement("a");
          a.href = url;
          a.download = "workflow.json";
          a.click();
          URL.revokeObjectURL(url);
        });
      }
    }
  ]
});
```

## キーバインディング例

```javascript theme={null}
app.registerExtension({
  name: "KeybindingExamples",
  commands: [
    /* 上記で定義されたコマンド */
  ],
  keybindings: [
    // Ctrl+R でワークフローを実行
    {
      combo: { key: "r", ctrl: true },
      commandId: "runWorkflow"
    },
    // Ctrl+Shift+C でワークフローをクリア
    {
      combo: { key: "c", ctrl: true, shift: true },
      commandId: "clearWorkflow"
    },
    // Ctrl+S でワークフローを保存
    {
      combo: { key: "s", ctrl: true },
      commandId: "saveWorkflow"
    },
    // F5 でワークフローを実行（代替）
    {
      combo: { key: "F5" },
      commandId: "runWorkflow"
    }
  ]
});
```

## 注意事項と制限

* ComfyUI コアで定義されたキーバインディングは、拡張機能によって上書きできません。これらのソースファイルでコアキーバインディングを確認してください：
  * [コアコマンド](https://github.com/Comfy-Org/ComfyUI_frontend/blob/e76e9ec61a068fd2d89797762f08ee551e6d84a0/src/composables/useCoreCommands.ts)
  * [コアメニューコマンド](https://github.com/Comfy-Org/ComfyUI_frontend/blob/e76e9ec61a068fd2d89797762f08ee551e6d84a0/src/constants/coreMenuCommands.ts)
  * [コアキーバインディング](https://github.com/Comfy-Org/ComfyUI_frontend/blob/e76e9ec61a068fd2d89797762f08ee551e6d84a0/src/constants/coreKeybindings.ts)
  * [予約済みキー組み合わせ](https://github.com/Comfy-Org/ComfyUI_frontend/blob/e76e9ec61a068fd2d89797762f08ee551e6d84a0/src/constants/reservedKeyCombos.ts)

* 一部のキー組み合わせはブラウザによって予約されており（検索用の Ctrl+F など）、上書きできません

* 複数の拡張機能が同じキーバインディングを登録した場合、動作は未定義です
