minor beautification of keyhandling

This commit is contained in:
Knut Forkalsrud 2010-02-13 12:34:11 -08:00
parent 4622a67f9e
commit fd8a5a2ce1

View file

@ -6,7 +6,7 @@ var ctx;
var locationx;
var locationy;
var autoscale = false;
var radius = 1; // the radius of the circle whe put the photo inside
var radius = 1; // the radius of the circle where put the photo inside
var zoomfactor = 1;
var baseCoordZoom;
var trX = 0;
@ -100,32 +100,34 @@ function mouseWheel(event) {
mouseMove(event);
}
function keyhandler(event) {
var keyCode;
var doDraw = false;
document.onkeydown = function(event) {
var keyCode;
var doDraw = false;
if (event == null) {
keyCode = window.event.keyCode;
} else {
keyCode = event.keyCode;
}
switch (keyCode) {
// left
case 37:
rotation += rotationStep;
doDraw = true;
break;
// right
case 39:
rotation -= rotationStep;
doDraw = true;
break;
default:
break;
}
if (doDraw) {
draw();
}
}
if (event == null) {
keyCode = window.event.keyCode;
} else {
keyCode = event.keyCode;
}
switch (keyCode) {
// left
case 37:
rotation += rotationStep;
doDraw = true;
break;
// right
case 39:
rotation -= rotationStep;
doDraw = true;
break;
default:
break;
}
if (doDraw) {
draw();
}
}
document.onkeypress = keyhandler;
document.onkeydown = keyhandler;