By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,384 Members | 1,794 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,384 IT Pros & Developers. It's quick & easy.

Catching cursorkeys in IE

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a


F. Da Costa wrote:
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.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

P: n/a
F. Da Costa wrote:
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).
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

Jul 20 '05 #3

P: n/a
F. Da Costa wrote:
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
Jul 20 '05 #4

P: n/a
Thomas 'PointedEars' Lahn <Po*********@web.de> writes:
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
--
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 20 '05 #5

P: n/a
JRS: In article <3F**************@PointedEars.de>, seen in
news:comp.lang.javascript, Thomas 'PointedEars' Lahn
<Po*********@web.de> posted at Mon, 15 Dec 2003 00:21:46 :-
F. Da Costa wrote:
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.
...

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.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 20 '05 #6

P: n/a
Lasse Reichstein Nielsen wrote:
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
Jul 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.