2013-12-05 11:14:12 +01:00
|
|
|
var keyboardShortcutsEnabled = true;
|
2014-01-16 23:28:58 +01:00
|
|
|
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.");
|
2014-01-17 00:21:29 +01:00
|
|
|
},
|
|
|
|
"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
|
|
|
}
|
|
|
|
};
|
2013-12-05 11:14:12 +01:00
|
|
|
|
|
|
|
function initKeyboard() {
|
|
|
|
|
|
|
|
$(document).keypress(function(event) {
|
|
|
|
|
2014-01-16 23:28:58 +01:00
|
|
|
if (keyboardEscapeEnterEnabled) {
|
|
|
|
switch (event.keyCode) {
|
|
|
|
case 13:
|
|
|
|
$(document).trigger("onEnterKey");
|
|
|
|
break;
|
|
|
|
case 27:
|
|
|
|
$(document).trigger("onEscapeKey");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-05 11:14:12 +01:00
|
|
|
if (!keyboardShortcutsEnabled) return;
|
2014-01-15 20:16:46 +01:00
|
|
|
if (event.ctrlKey && event.altKey && ! event.metaKey) processWords(event);
|
2014-01-15 14:20:49 +01:00
|
|
|
if (event.altKey || event.ctrlKey || event.metaKey) return; //ignore key presses with modifier keys except shift
|
2013-12-05 11:14:12 +01:00
|
|
|
|
|
|
|
var ch = String.fromCharCode(event.which);
|
|
|
|
|
|
|
|
switch (ch) {
|
|
|
|
case 'c': clearDoodle(); break;
|
2013-12-05 11:50:02 +01:00
|
|
|
case 'n': clearDoodle(); break;
|
2013-12-05 11:14:12 +01:00
|
|
|
case 'p': print(); break;
|
|
|
|
case 'u': oopsUndo(); break;
|
2014-01-09 17:05:03 +01:00
|
|
|
case 'g': settingsWindow.downloadGcode(); break;
|
2013-12-05 11:14:12 +01:00
|
|
|
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;
|
|
|
|
case 'L': nextDoodle(); break;
|
|
|
|
case 'l': prevDoodle(); break;
|
2013-12-05 11:14:12 +01:00
|
|
|
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 ';': 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;
|
|
|
|
|
2014-01-17 00:21:29 +01:00
|
|
|
//default: console.log("Key: '" + ch + "' (" + event.which + ")");
|
2013-12-05 11:14:12 +01:00
|
|
|
}
|
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
|
|
|
|
}
|
2013-12-05 11:14:12 +01:00
|
|
|
})
|
|
|
|
|
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 = "";
|
|
|
|
}
|
|
|
|
}
|