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

77 lines
2.0 KiB
JavaScript
Raw Normal View History

var keyboardShortcutsEnabled = true;
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.");
}
};
function initKeyboard() {
$(document).keypress(function(event) {
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) {
case 'c': clearDoodle(); break;
2013-12-05 11:50:02 +01:00
case 'n': clearDoodle(); 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;
case 'L': nextDoodle(); break;
case 'l': prevDoodle(); 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 ';': 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 = "";
}
}