This seems to do the trick. I decided to just not use typematic repeat for any browser, that way they all can follow the path I originally set out for Opera. However, with them all following that path, things got both a little simpler, and a little more complex:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function goPic(e){
if(goPic.running) return;
goPic.running = true;
e = e || window.event;
var goPic2 = function(){
goPic.i = k == 68? goPic.i + 1 : k == 65? goPic.i - 1 : goPic.i;
document.getElementById('myimage').style.left = goPic.i + 'px';
goPic.timer = setTimeout(goPic2, 20);
}, k = e.keyCode || e.which;
document.getElementById('myimage').style.position = "relative";
goPic2();
//test
//document.getElementById('myinput').value = goPic.i;
};
goPic.i = 0;
goPic.stopPic = function(){
goPic.running = false;
clearTimeout(goPic.timer);
};
document.onkeydown = goPic;
document.onkeyup = goPic.stopPic;
</script>
</head>
<body>
<input id="myinput">w=87, a=65, s=83, d=68,
<br>
<img id="myimage" src="smiley.gif" width="32" height="32" alt="pic">
</body>
</html>
Notes: I also changed the code to expose only one global variable (goPic). This could also probably be done without exposing any globals, but that would make it a bit more complicated to integrate it into certain other types of code.
Added Later:
Code:
i = k == 68? i + 1 : k == 65? i - 1 : i;
is just shorthand for:
Code:
if(k == 68)
i = i + 1;
else if (k == 65)
i = i - 1;
else
i = i;
Bookmarks