Tony <someone@somewhere.not> wrote in message
news:118hqac9lvnap3d@corp.supernews.com...[color=blue]
> I'm having trouble getting Opera to recognize a repeating key event - I[/color]
was[color=blue]
> wondering if anyone had experience with this.
>
> Basically, I am trying to move a <div> based on the arrow keys that are
> pressed - left/right motion as you press the left & right arrow keys. I[/color]
want[color=blue]
> the element to move as long as the key is held down.
>
> The code I'm using is:
>
>
> This works for IE, Netscape, and Firefox, no problems. But Opera won't[/color]
read[color=blue]
> the autorepeat of the key, so it only moves once each time you press the
> key.
>
> Any thoughts on a workaround for it?
>
>[/color]
Set an interval when the key is pressed, and cancel it on release:
var moveInterval=null;
function readArrow(e)
{
clearInterval( moveInterval );
movePaddle( key=window.event ? event.keyCode : e.which );
moveInterval=setInterval('movePaddle('+ key+' ) ', 100);
}
function movePaddle( key )
{
if ((key == 37) && (padX > padMinX)) { padX-=5; }
else if ((key == 39) && (padX < padMaxX)) { padX+=5; }
document.getElementById("paddle").style["left"]=padX;
}
<body onKeyDown="movePaddle(event);" onkeyup='clearInterval(moveInterval)'>
--
Stephen Chalmers
http://makeashorterlink.com/?H3E82245A
547265617375726520627572696564206174204F2E532E2072 65663A205451323437393134