You should do something like this:
document.onkeydown = function(event) {
...
}
document.onkeyup = function(event) {
...
}
And get rid of:
onkeyup="onKeyUp();" onkeydown="onKeydown();"
The quick check page I created that works:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
document.onkeydown = function(event) {
event = event || window.event;
var e = event.keyCode;
up = true;
throw('up');
if (e==65 ){
left = true;
}
if (e==83 ){
down = true;
}
if (e==68 ){
right = true;
}
}
document.onkeyup=function(event) {
event = event || window.event;
var e = event.keyCode;
up = false;
throw('up');
if (e==65 ){
left = false;
}
if (e==83 ){
down = false;
}
if (e==68 ){
right = false;
}
}
</script>
</head>
<body>
<input id="ss" type="button" value="start/stop" />
<div id="container" style="border:1px solid; cursor:none; width:480px; height:320px;">
<canvas id="canvas" width="480" height="320">
Canvas not displaying.
</canvas>
</div>
</body>
</html>
source
share