开发
简体中文
app.registerExtension({ name: "MyExtension", // 注册命令 commands: [ { id: "myCommand", label: "我的命令", function: () => { console.log("命令已执行!"); } } ], // 将快捷键与命令关联 keybindings: [ { combo: { key: "k", ctrl: true }, commandId: "myCommand" } ] });
id
label
function
{ id: string, // 命令的唯一标识符 label: string, // 命令显示名称 function: () => void // 命令被触发时执行的函数 }
combo
commandId
{ 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"
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); }); } } ] });
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" } ] });
此页面对您有帮助吗?