moves keybinds to sep file, update readme

This commit is contained in:
EllangoK 2023-04-13 06:14:23 -04:00
parent dd3aa2f0a3
commit 9af0dbd7f8
3 changed files with 61 additions and 54 deletions

View File

@ -35,24 +35,26 @@ Workflow examples can be found on the [Examples page](https://comfyanonymous.git
| Keybind | Explanation | | Keybind | Explanation |
| - | - | | - | - |
| Enter | Queues up current graph for generation | | Ctrl + Enter | Queues up current graph for generation |
| Ctrl + Shift + Enter | Queues up current graph as first for generation |
| Ctrl + S | Saves workflow |
| Ctrl + O | Load workflow |
| Ctrl + A | Select all nodes | | Ctrl + A | Select all nodes |
| Ctrl + M | Mute/unmute selected nodes | | Ctrl + M | Mute/unmute selected nodes |
| Delete/Backspace | Delete selected nodes | | Delete/Backspace | Delete selected nodes |
| Ctrl + Delete/Backspace | Delete the current graph |
| Space | Move the canvas around when held and moving the cursor | | Space | Move the canvas around when held and moving the cursor |
| Ctrl/Shift + Click | Add clicked node to selection | | Ctrl/Shift + Click | Add clicked node to selection |
| Ctrl + C/Ctrl + V | Copy and paste selected nodes (without maintaining connections to outputs of unselected nodes) | | Ctrl + C/Ctrl + V | Copy and paste selected nodes (without maintaining connections to outputs of unselected nodes) |
| Ctrl + C/Ctrl + Shift + V| Copy and paste selected nodes (maintaining connections from outputs of unselected nodes to inputs of pasted nodes) | | Ctrl + C/Ctrl + Shift + V| Copy and paste selected nodes (maintaining connections from outputs of unselected nodes to inputs of pasted nodes) |
| Shift + Drag | Move multiple selected nodes at the same time | | Shift + Drag | Move multiple selected nodes at the same time |
| F | Places current graph at the front of the queue |
| Q | Toggles visibility of the queue | | Q | Toggles visibility of the queue |
| H | Toggles visibility of history | | H | Toggles visibility of history |
| S | Saves current graph as json |
| L | Brings up file input to load graphs |
| R | Refreshes graph | | R | Refreshes graph |
| C | Clears graph |
| D | Loads default graph | | D | Loads default graph |
Ctrl can also be replaced with Cmd instead for MacOS users
# Installing # Installing
## Windows ## Windows

View File

@ -1,4 +1,5 @@
import { app } from "/scripts/app.js"; import { app } from "/scripts/app.js";
import { $el } from "/scripts/ui.js";
const id = "Comfy.Keybinds"; const id = "Comfy.Keybinds";
app.registerExtension({ app.registerExtension({
@ -11,17 +12,66 @@ app.registerExtension({
return; return;
} }
const modifierPressed = event.ctrlKey || event.metaKey;
// Queue prompt using ctrl or command + enter
if (modifierPressed && (event.key === "Enter" || event.keyCode === 13 || event.keyCode === 10)) {
app.queuePrompt(event.shiftKey ? -1 : 0);
}
// Save workflow using ctrl or command + s
if (modifierPressed && (event.key === "s" || event.keyCode === 83)) {
event.preventDefault();
const json = JSON.stringify(app.graph.serialize(), null, 2); // convert the data to a JSON string
const blob = new Blob([json], { type: "application/json" });
const url = URL.createObjectURL(blob);
const defaultFileName = "workflow.json";
const userFileName = prompt("Save workflow as:", defaultFileName);
if (userFileName === null) return;
const fileName = userFileName ? userFileName : defaultFileName;
if (!fileName.endsWith(".json")) {
fileName += ".json";
}
const a = $el("a", {
href: url,
download: fileName,
style: { display: "none" },
parent: document.body,
});
a.click();
setTimeout(() => {
a.remove();
window.URL.revokeObjectURL(url);
}, 0);
}
// Load workflow using ctrl or command + o
if (modifierPressed && (event.key === "o" || event.keyCode === 79)) {
event.preventDefault();
const fileInput = document.querySelector("#comfy-file-input");
fileInput.click()
}
// Delete all nodes using ctrl or command + backspace or delete
if (modifierPressed && ((event.key === "Backspace" || event.keyCode === 8) || (event.key === "Delete" || event.keyCode === 46))) {
const clearButton = document.querySelector("#clear-button");
clearButton.click()
}
// Finished Handling all modifier keybinds, now handle the rest
if (event.ctrlKey || event.altKey || event.metaKey) { if (event.ctrlKey || event.altKey || event.metaKey) {
return; return;
} }
const keyToButtonIdMap = { const keyToButtonIdMap = {
"Enter": "queue-button",
"f": "queue-front-button",
"q": "view-queue-button", "q": "view-queue-button",
"h": "view-history-button", "h": "view-history-button",
"r": "refresh-button", "r": "refresh-button",
"c": "clear-button",
"d": "load-default-button", "d": "load-default-button",
}; };
@ -32,6 +82,6 @@ app.registerExtension({
} }
} }
document.addEventListener("keyup", keybindListener); window.addEventListener("keydown", keybindListener, true);
} }
}); });

View File

@ -18,7 +18,6 @@ class ComfyApp {
this.ui = new ComfyUI(this); this.ui = new ComfyUI(this);
this.extensions = []; this.extensions = [];
this.nodeOutputs = {}; this.nodeOutputs = {};
this.shiftDown = false;
} }
/** /**
@ -688,49 +687,6 @@ class ComfyApp {
api.init(); api.init();
} }
#addKeyboardHandler() {
window.addEventListener("keydown", (e) => {
this.shiftDown = e.shiftKey;
const modifierPressed = e.ctrlKey || e.metaKey;
// Queue prompt using ctrl or command + enter
if (modifierPressed && (e.key === "Enter" || e.keyCode === 13 || e.keyCode === 10)) {
this.queuePrompt(e.shiftKey ? -1 : 0);
}
// Save workflow using ctrl or command + s
if (modifierPressed && (e.key === "s" || e.keyCode === 83)) {
e.preventDefault();
const json = JSON.stringify(app.graph.serialize(), null, 2); // convert the data to a JSON string
const blob = new Blob([json], { type: "application/json" });
const url = URL.createObjectURL(blob);
const a = $el("a", {
href: url,
download: "workflow.json",
style: { display: "none" },
parent: document.body,
});
a.click();
setTimeout(function () {
a.remove();
window.URL.revokeObjectURL(url);
}, 0);
}
// Load workflow using ctrl or command + o
if (modifierPressed && (e.key === "o" || e.keyCode === 79)) {
e.preventDefault();
const fileInput = document.querySelector("#comfy-file-input");
fileInput.click()
}
});
window.addEventListener("keyup", (e) => {
this.shiftDown = e.shiftKey;
});
}
/** /**
* Loads all extensions from the API into the window * Loads all extensions from the API into the window
*/ */
@ -807,7 +763,6 @@ class ComfyApp {
this.#addApiUpdateHandlers(); this.#addApiUpdateHandlers();
this.#addDropHandler(); this.#addDropHandler();
this.#addPasteHandler(); this.#addPasteHandler();
this.#addKeyboardHandler();
await this.#invokeExtensionsAsync("setup"); await this.#invokeExtensionsAsync("setup");
} }