hi,
I am trying to write a js program which counts keyboard clicks.
The problem I have is stopping auto-repeat, i.e. if the key is held down for a long time it counts this as lots of clicks instead of just one.
So far I have only tested in Safari on OS x and IE on Windows.
It is IE that is giving me the trouble.
I am a bit of a noobie, and starting to wonder if what I want to do is possible- maybe I should try some other way?
I added in what I could find that is supposed to stop default behaviour:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN">
<html>

<head>
<title></title>
<script type="text/javascript" src="soundmanager.js">
</script>
<script type="text/javascript">
<!--
/* timed beeps at 10sec intervals for 1 min */
var foo = 0;
function beep(){
if (foo < 7) {
foo++;
if (foo > 1) {
soundManager.play('on');
}
setTimeout("beep()",10000);
}
else {
alert('session over');
}
}
/*counting key presses: this is the problem area, where I have added everything I could find to stop the auto-repeat*/
var totalKeyStrokes = 0;
function CountKeyStrokes() {
if (foo % 2 == 0) {
totalKeyStrokes = ++totalKeyStrokes;
if (evt.preventDefault) {
evt.preventDefault();
}
else {
evt.returnValue = false;
return false;
}
}
}
document.onkeydown = CountKeyStrokes;
//-->
</script>
</head>
<body onload="beep()";>
<div>
</div>
<script>
soundManagerInit();
</script>
some text here
<form name="go">
<input type="button" value="Start" onClick="alert(totalKeyStrokes)">
</form>
</body>
</html>