Catching cursorkeys in IE

F

F. Da Costa

Hi,

The following snip works totally ok in a Gecko browser, for the 'normal keys as well as the cursorkeys.

<p>Key in the searchable 'thing':<br />
<input type="text" value="" id="txt1" onkeypress="var e= event; alert(e.keyCode);" />
</p>

In IE 5+ however the cursokeys do NOT register at all.
Insofar as I have been able to gather the keyCode property should be supported by IE (which is probably a
misundestanding from my side).
What *would* be the correct way to catch the cursorkeys?

TIA
Fermin DCG
 
M

Martin Honnen

F. Da Costa said:
The following snip works totally ok in a Gecko browser, for the 'normal
keys as well as the cursorkeys.

<p>Key in the searchable 'thing':<br />
<input type="text" value="" id="txt1" onkeypress="var e= event;
alert(e.keyCode);" />
</p>

In IE 5+ however the cursokeys do NOT register at all.
Insofar as I have been able to gather the keyCode property should be
supported by IE (which is probably a misundestanding from my side).
What *would* be the correct way to catch the cursorkeys?

I think IE fires only keydown and keyup events for cursor keys.
 
F

F. Da Costa

F. Da Costa said:
Hi,

The following snip works totally ok in a Gecko browser, for the 'normal
keys as well as the cursorkeys.

<p>Key in the searchable 'thing':<br />
<input type="text" value="" id="txt1" onkeypress="var e= event;
alert(e.keyCode);" />
</p>
MS does not like onKeyPress! Using onKeyDown seems to work ok (don't ask why).
 
T

Thomas 'PointedEars' Lahn

F. Da Costa said:
The following snip works totally ok in a Gecko browser, for the 'normal keys as well as the cursorkeys.

RFC 2822, section 2.1.1, calls for a reasonable maximum of 78 characters
per line. Please set your automagic linebreak then to recommended 72 to
76 characters per line in order not to exceed that maximum when quoting
others or being quoted. I guess the preference can be set with Edit,
Preferences, Composition, Composing Messages, Wrap plain text messages
at [__] characters in Mozilla Thunderbird as it can in Mozilla MailNews.
For I know that Thunderbird is a comparably young project, if there is
no preference (RTFM!) you should consider to update your Thunderbird.
<p>Key in the searchable 'thing':<br />
<input type="text" value="" id="txt1" onkeypress="var e= event; alert(e.keyCode);" />
</p>

In addition to what Martin wrote:

Do not declare a global variable in an event handler.
For general keyboard event handling, you would use

function handlerFunction(e)
{
var keyCode =
(e.which
? e.which
: (e.keyCode
? e.keyCode
: 0));

if (keyCode ...)
{
...
}
}

<... onwhatever="handlerFunction(event);" ...>


HTH

PointedEars
 
L

Lasse Reichstein Nielsen

Thomas 'PointedEars' Lahn said:
function handlerFunction(e)
{
var keyCode =
(e.which
? e.which
: (e.keyCode
? e.keyCode
: 0));

FWIW, (foo ? foo : bar) can be written shorter as (foo || bar).
That means that your code above can be written as
var keyCode = e.which || e.keyCode || 0;

/L
 
T

Thomas 'PointedEars' Lahn

Lasse said:
FWIW, (foo ? foo : bar) can be written shorter as (foo || bar).
That means that your code above can be written as
var keyCode = e.which || e.keyCode || 0;

n1, thx :)


\V/ PointedEars
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
Thomas 'PointedEars' Lahn
as well as the cursorkeys.

RFC 2822, section 2.1.1, calls for a reasonable maximum of 78 characters
per line. Please set your automagic linebreak then to recommended 72 to
76 characters per line in order not to exceed that maximum when quoting
others or being quoted.
...


That should not be done, except in a truly intelligent editor, if you
are likely to want to post long lines of HTML or of script (which you
did).

It is of *primary* importance that script, at least, should not be
artificially broken.

The need, therefore, with most systems, is to post with margins at least
as wide as the included code. Obviously, it is then a good thing to
write your HTML, and your script, within a reasonable margin of about 72
characters; and, if you cannot do so, you need to control the length of
lines in plain text by other means, such as by inserting breaks
manually.

TL is a Mussolini wannabe, but does not really understand the proper use
of News.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top