2016-12-31 12:37:10 -05:00
|
|
|
function Keyboard()
|
|
|
|
{
|
2017-11-06 21:41:41 -05:00
|
|
|
this.listen = function(e)
|
2016-12-31 12:37:10 -05:00
|
|
|
{
|
2017-11-05 14:53:59 -05:00
|
|
|
// save
|
2017-11-06 21:41:41 -05:00
|
|
|
if(e.key == "s" && (e.ctrlKey || e.metaKey)){
|
2017-11-05 14:53:59 -05:00
|
|
|
dotgrid.export();
|
|
|
|
return;
|
|
|
|
}
|
2017-11-05 14:38:14 -05:00
|
|
|
|
2017-11-05 20:10:37 -05:00
|
|
|
// undo
|
2017-11-06 21:41:41 -05:00
|
|
|
if(e.key == "z" && (e.ctrlKey || e.metaKey)){
|
2017-11-05 20:10:37 -05:00
|
|
|
dotgrid.erase();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-06 21:41:41 -05:00
|
|
|
// Reset
|
|
|
|
if((e.key == "Backspace" || e.key == "Delete") && e.ctrlKey && e.shiftKey){
|
|
|
|
e.preventDefault();
|
|
|
|
dotgrid.theme.reset();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (e.keyCode) {
|
|
|
|
case 83 : dotgrid.draw_arc(e.shiftKey ? "1,1" : "0,1"); break; // 'S'
|
|
|
|
case 65 : dotgrid.draw_arc(e.shiftKey ? "1,0" : "0,0"); break; // 'a'
|
2017-11-05 15:51:16 -05:00
|
|
|
case 68 : dotgrid.draw_line(); break; // 'd'
|
|
|
|
case 70 : dotgrid.draw_bezier(); break; // 'f'
|
|
|
|
case 82 : dotgrid.draw_close(); break; // 'r'
|
|
|
|
case 187 : dotgrid.mod_thickness(1); break; // '+'
|
|
|
|
case 189 : dotgrid.mod_thickness(-1); break; // '-'
|
2017-11-05 20:10:37 -05:00
|
|
|
case 221 : dotgrid.mod_thickness(1); break; // ']'
|
|
|
|
case 219 : dotgrid.mod_thickness(-1); break; // '['
|
2017-11-05 15:51:16 -05:00
|
|
|
case 191 : dotgrid.mod_linecap(1); break; // '/'
|
2017-11-05 20:10:37 -05:00
|
|
|
|
|
|
|
case 32 : dotgrid.mirror = dotgrid.mirror == true ? false : true; dotgrid.draw(); break; // 'space'
|
2016-12-31 15:55:35 -05:00
|
|
|
|
2017-11-05 15:51:16 -05:00
|
|
|
case 81 : dotgrid.reset(); break; // 'Q'
|
|
|
|
case 27 : dotgrid.reset(); break; // 'ESC'
|
|
|
|
case 87 : dotgrid.erase(); break; // 'W'
|
|
|
|
case 8 : dotgrid.erase(); break; // 'Backspace'
|
|
|
|
case 69 : dotgrid.export(); break; // 'e'
|
2017-11-05 20:10:37 -05:00
|
|
|
case 13 : dotgrid.export(); break; // 'e'
|
|
|
|
|
2017-11-06 21:41:41 -05:00
|
|
|
case 9 : dotgrid.toggle_fill(); e.preventDefault(); break; // 'tab'
|
2017-01-04 12:48:08 -05:00
|
|
|
|
2017-11-05 19:18:57 -05:00
|
|
|
case 38 : dotgrid.mod_move(0,-10); break; // 'up'
|
|
|
|
case 40 : dotgrid.mod_move(0,10); break; // 'down'
|
|
|
|
case 37 : dotgrid.mod_move(-10,0); break; // 'left'
|
|
|
|
case 39 : dotgrid.mod_move(10,0); break; // 'right'
|
2016-12-31 12:37:10 -05:00
|
|
|
}
|
2017-11-04 19:59:11 -04:00
|
|
|
dotgrid.draw();
|
2016-12-31 12:37:10 -05:00
|
|
|
}
|
|
|
|
}
|