473,320 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Opera problem with onkeydown

I'm having trouble getting Opera to recognize a repeating key event - I was
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 want
the element to move as long as the key is held down.

The code I'm using is:

function movePaddle(e) {
if (window.event) {
key=event.keyCode;
} else {
key = e.which;
}
if ((key == 37) && (padX > padMinX)) { padX-=5; }
else if ((key == 39) && (padX < padMaxX)) { padX+=5; }
document.getElementById("paddle").style["left"]=padX;
}

And in the body:

<body onKeyDown="javascript:movePaddle(event);">

This works for IE, Netscape, and Firefox, no problems. But Opera won't read
the autorepeat of the key, so it only moves once each time you press the
key.

Any thoughts on a workaround for it?
Jul 23 '05 #1
4 2540
"Tony" <so*****@somewhere.not> writes:
[no autorepeat onkeydown event in Opera]
Any thoughts on a workaround for it?


Don't rely on autorepeat. Let it move from the first keydown to
the first keyup, and ignore the keydowns in between.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #2

Tony <so*****@somewhere.not> wrote in message
news:11*************@corp.supernews.com...
I'm having trouble getting Opera to recognize a repeating key event - I was 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 want 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 read the autorepeat of the key, so it only moves once each time you press the
key.

Any thoughts on a workaround for it?


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

Jul 23 '05 #3
"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:64**********@hotpop.com...
"Tony" <so*****@somewhere.not> writes:
[no autorepeat onkeydown event in Opera]
Any thoughts on a workaround for it?


Don't rely on autorepeat. Let it move from the first keydown to
the first keyup, and ignore the keydowns in between.


That was one of the possibilities I was considering - I'll have to play with
it tonight
Jul 23 '05 #4
"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:64**********@hotpop.com...
"Tony" <so*****@somewhere.not> writes:
[no autorepeat onkeydown event in Opera]
Any thoughts on a workaround for it?


Don't rely on autorepeat. Let it move from the first keydown to
the first keyup, and ignore the keydowns in between.


It worked - thanks!

One tweak was needed, though: the autorepeat caused the paddle to begin
moving faster when it kicked in (bunches of keydown events firing off) - so
I had to put a check to see if the keypress status was already set, before
setting it again -

But it works on Opera now, too.

http://www.dslextreme.com/~tony23/bricks.htm
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: euler | last post by:
why did the keydown event not fire in this simple example? <HTML> <HEAD><title>keydown_div</title> <script type="text/javascript"> function keydown() { alert("keydown"); } </script>
10
by: b.dam | last post by:
I'm trying the following: function grid() { this._el = document.createElement("TABLE"); var self = this; document.addEventListener("onkeydown", function(event) {self.gridKeyDown(event);},...
2
by: Iver Erling Årva | last post by:
I have come across a problem with the onKeyDown event in some of my forms. I'm using onKeyDown in <form> as a standard method to open my help screen system throughout my system, but I have...
5
by: Roger Withnell | last post by:
I'm using the following code to start a function on key down. document.onkeydown = OnKeyDown; function OnKeyDown() { vKeyCode = event.keyCode; ..code... }
5
by: Robert S | last post by:
I am using the following to prevent the Enter key from submitting my form (this would have undesirable results): (index.html) <body onkeydown="rejectEnter( event )"> (functions.js) function...
3
by: Paul Gorodyansky | last post by:
Hi, I have function that works via onkeypressed - for example, what to catch when a user presses a punctuation symbol such as '.' So I check keyCode for that - works just fine in Opera 8,...
0
by: =?Utf-8?B?Q0dX?= | last post by:
I have a .NET 1.1 application which uses several grids of text boxs (in repeaters and datagrids) for entering arrays of time values. I use onkeydown to allow users to navigate through the grids...
1
eboyjr14
by: eboyjr14 | last post by:
I have this UserScript for Grease monkey. but I can't get the onleydown event to fire in FIREFOX only. I've looked everywhere! // ==UserScript== // @name iGoogle Suggest //...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.