2019-03-27 02:20:54 +03:00
|
|
|
var spacePressed = false;
|
|
|
|
|
2020-12-31 18:47:56 +03:00
|
|
|
/** Just listens to hotkeys and calls the linked functions
|
|
|
|
*
|
|
|
|
* @param {*} e
|
|
|
|
*/
|
2019-03-27 02:20:54 +03:00
|
|
|
function KeyPress(e) {
|
2020-04-04 10:41:56 +03:00
|
|
|
var keyboardEvent = window.event? event : e;
|
2020-03-05 18:13:23 +03:00
|
|
|
|
2020-06-23 18:34:03 +03:00
|
|
|
//if the user is typing in an input field or renaming a layer, ignore these hotkeys, unless it's an enter key
|
|
|
|
if (document.activeElement.tagName == 'INPUT' || isRenamingLayer) {
|
|
|
|
if (e.keyCode == 13) {
|
|
|
|
currentLayer.closeOptionsMenu();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2020-03-05 18:13:23 +03:00
|
|
|
|
2020-04-04 10:41:56 +03:00
|
|
|
//if no document has been created yet,
|
|
|
|
//orthere is a dialog box open
|
|
|
|
//ignore hotkeys
|
|
|
|
if (!documentCreated || dialogueOpen) return;
|
2020-03-05 18:13:23 +03:00
|
|
|
|
|
|
|
//
|
|
|
|
if (e.key === "Escape") {
|
2020-04-09 17:48:19 +03:00
|
|
|
if (!selectionCanceled) {
|
2020-04-15 03:01:31 +03:00
|
|
|
tool.pencil.switchTo();
|
2020-04-09 17:48:19 +03:00
|
|
|
}
|
2020-03-05 18:13:23 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (keyboardEvent.keyCode) {
|
|
|
|
//pencil tool - 1, b
|
2020-04-15 03:01:31 +03:00
|
|
|
case 49: case 66:
|
|
|
|
tool.pencil.switchTo();
|
2020-03-05 18:13:23 +03:00
|
|
|
break;
|
2020-04-20 17:55:34 +03:00
|
|
|
// copy tool c
|
|
|
|
case 67: case 99:
|
|
|
|
if (keyboardEvent.ctrlKey && !dragging && currentTool.name == 'moveselection') {
|
|
|
|
copySelection();
|
|
|
|
}
|
|
|
|
break;
|
2020-03-05 18:13:23 +03:00
|
|
|
//fill tool - 2, f
|
|
|
|
case 50: case 70:
|
2020-04-15 03:01:31 +03:00
|
|
|
tool.fill.switchTo();
|
2020-03-05 18:13:23 +03:00
|
|
|
break;
|
|
|
|
//eyedropper - 3, e
|
|
|
|
case 51: case 69:
|
2020-04-15 03:01:31 +03:00
|
|
|
tool.eyedropper.switchTo();
|
2020-03-05 18:13:23 +03:00
|
|
|
break;
|
|
|
|
//pan - 4, p,
|
|
|
|
case 52: case 80:
|
2020-04-15 03:01:31 +03:00
|
|
|
tool.pan.switchTo();
|
2020-03-05 18:13:23 +03:00
|
|
|
break;
|
2021-01-14 21:04:39 +03:00
|
|
|
case 76:
|
|
|
|
tool.line.switchTo();
|
|
|
|
break;
|
2020-03-05 18:13:23 +03:00
|
|
|
//zoom - 5
|
|
|
|
case 53:
|
2020-04-15 03:01:31 +03:00
|
|
|
tool.zoom.switchTo();
|
2020-03-05 18:13:23 +03:00
|
|
|
break;
|
|
|
|
// eraser -6, r
|
|
|
|
case 54: case 82:
|
2020-04-15 03:01:31 +03:00
|
|
|
tool.eraser.switchTo()
|
2020-03-05 18:13:23 +03:00
|
|
|
break;
|
2020-04-15 03:01:31 +03:00
|
|
|
// Rectangular selection
|
2020-03-05 18:13:23 +03:00
|
|
|
case 77: case 109:
|
2020-04-15 03:01:31 +03:00
|
|
|
tool.rectselect.switchTo()
|
2021-04-28 23:55:36 +03:00
|
|
|
break;
|
|
|
|
// rectangle tool, u
|
|
|
|
case 85:
|
|
|
|
tool.rectangle.switchTo()
|
2020-03-05 18:13:23 +03:00
|
|
|
break;
|
2020-04-20 17:55:34 +03:00
|
|
|
// Paste tool
|
|
|
|
case 86: case 118:
|
|
|
|
if (keyboardEvent.ctrlKey && !dragging) {
|
|
|
|
pasteSelection();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 88: case 120:
|
|
|
|
if (keyboardEvent.ctrlKey && !dragging && currentTool.name == 'moveselection') {
|
|
|
|
cutSelectionTool();
|
|
|
|
tool.pencil.switchTo();
|
|
|
|
}
|
|
|
|
break;
|
2020-03-05 18:13:23 +03:00
|
|
|
//Z
|
|
|
|
case 90:
|
|
|
|
//CTRL+ALT+Z redo
|
2020-04-15 03:01:31 +03:00
|
|
|
if (keyboardEvent.altKey && keyboardEvent.ctrlKey)
|
2020-03-05 18:13:23 +03:00
|
|
|
redo();
|
2020-04-09 17:48:19 +03:00
|
|
|
if (!selectionCanceled) {
|
2020-04-15 03:01:31 +03:00
|
|
|
tool.pencil.switchTo()
|
2020-04-09 17:48:19 +03:00
|
|
|
}
|
2020-03-05 18:13:23 +03:00
|
|
|
//CTRL+Z undo
|
2020-04-09 17:48:19 +03:00
|
|
|
else if (keyboardEvent.ctrlKey) {
|
|
|
|
undo();
|
|
|
|
if (!selectionCanceled) {
|
2020-04-15 03:01:31 +03:00
|
|
|
tool.pencil.switchTo()
|
2020-04-09 17:48:19 +03:00
|
|
|
}
|
|
|
|
}
|
2020-03-05 18:13:23 +03:00
|
|
|
//Z switch to zoom tool
|
2020-04-15 03:01:31 +03:00
|
|
|
else
|
|
|
|
tool.zoom.switchTo()
|
2020-03-05 18:13:23 +03:00
|
|
|
break;
|
|
|
|
//redo - ctrl y
|
|
|
|
case 89:
|
2020-04-15 03:01:31 +03:00
|
|
|
if (keyboardEvent.ctrlKey)
|
2020-03-05 18:13:23 +03:00
|
|
|
redo();
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
spacePressed=true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-03-27 02:20:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
document.onkeydown = KeyPress;
|
|
|
|
|
|
|
|
window.addEventListener("keyup", function (e) {
|
2020-04-15 03:01:31 +03:00
|
|
|
|
2019-03-27 02:20:54 +03:00
|
|
|
if (e.keyCode == 32) spacePressed = false;
|
|
|
|
|
|
|
|
});
|