0
0
mirror of https://github.com/Doodle3D/doodle3d-client.git synced 2024-11-16 07:37:57 +01:00
doodle3d-client/js/Keyboard.js

106 lines
2.7 KiB
JavaScript
Raw Normal View History

var keyboardShortcutsEnabled = true;
var keyboardEscapeEnterEnabled = false;
2014-01-15 20:16:46 +01:00
var wordBuffer = "";
var wordFuncs = {
"idbeholdl": function() {
alert("Light!");
},
"idspispopd": function() {
drawTextOnCanvas("Im in ur kanvas drawin' ur stuffz.");
},
"dia": function() {
var cx = canvasWidth / 2;
var cy = canvasHeight /2;
drawCircle(cx, cy, 50, 4);
shapeMoveTo(cx - 20, cy);
shapeLineTo(cx + 20, cy);
shapeMoveTo(cx, cy - 20);
shapeLineTo(cx, cy + 20);
2014-01-19 17:49:44 +01:00
},
"stats": function() {
var text = "Shape statistics:\nNumber of points: " + _points.length;
alert(text);
},
"pdump": function() {
console.log("points array: " + _points);
2014-01-15 20:16:46 +01:00
}
};
function initKeyboard() {
$(document).keypress(function(event) {
if (keyboardEscapeEnterEnabled) {
switch (event.keyCode) {
case 13:
$(document).trigger("onEnterKey");
break;
case 27:
$(document).trigger("onEscapeKey");
break;
}
}
if (!keyboardShortcutsEnabled) return;
2014-01-15 20:16:46 +01:00
if (event.ctrlKey && event.altKey && ! event.metaKey) processWords(event);
if (event.altKey || event.ctrlKey || event.metaKey) return; //ignore key presses with modifier keys except shift
var ch = String.fromCharCode(event.which);
switch (ch) {
2014-12-17 09:45:40 +01:00
case 'c': newSketch(); break;
case 'n': newSketch(); break;
case 'p': print(); break;
case 'u': oopsUndo(); break;
2014-01-09 17:05:03 +01:00
case 'g': settingsWindow.downloadGcode(); break;
case 'q': stopPrint(); break;
case ',': openSettingsWindow(); break;
2013-12-05 11:50:02 +01:00
case 'h': previewUp(true); break;
case 'H': previewDown(true); break;
case 's': saveSketch(); break;
2014-12-17 09:45:40 +01:00
case 'L': nextSketch(); break;
case 'l': prevSketch(); break;
case '[': previewTwistLeft(); break;
case ']': previewTwistRight(); break;
2014-01-09 17:05:03 +01:00
case '|': resetTwist(); break;
case 't': showWordArtDialog(); break;
case 'i': showShapeDialog(); break;
case 'T': showScanDialog(); break;
2014-01-09 17:05:03 +01:00
case ';': moveShape(-5,0); break;
case '\'': moveShape(5,0); break;
case '-': zoomShape(.95); break;
case '+': zoomShape(1.05); break;
case 'r': rotateShape(.1); break;
case 'R': rotateShape(-.1); break;
//default: console.log("Key: '" + ch + "' (" + event.which + ")");
}
2014-01-16 12:48:57 +01:00
if(event.which != 13) { // don't prevent enter usage, it's used in tour
event.preventDefault(); //prevents the character to end up in a focussed textfield
}
})
2014-01-15 20:16:46 +01:00
}
function processWords(e) {
wordBuffer += String.fromCharCode(e.which);
var match = false;
for (var k in wordFuncs) {
if (k.indexOf(wordBuffer) == 0) {
if (k.length == wordBuffer.length) match = wordFuncs[k];
else match = true;
break;
}
}
if (typeof(match) == 'function') {
match();
wordBuffer = "";
} else if (!match) {
wordBuffer = "";
}
}