Catching cursorkeys in IE

Discussion in 'Javascript' started by F. Da Costa, Dec 14, 2003.

  1. F. Da Costa

    F. Da Costa Guest

    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
     
    F. Da Costa, Dec 14, 2003
    #1
    1. Advertising

  2. 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/
     
    Martin Honnen, Dec 14, 2003
    #2
    1. Advertising

  3. F. Da Costa

    F. Da Costa Guest

    Re: Catching cursorkeys in IE (SOLVED)

    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
     
    F. Da Costa, Dec 14, 2003
    #3
  4. 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
     
    Thomas 'PointedEars' Lahn, Dec 14, 2003
    #4
  5. Thomas 'PointedEars' Lahn <> 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 -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Dec 15, 2003
    #5
  6. 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
     
    Thomas 'PointedEars' Lahn, Dec 15, 2003
    #6
  7. JRS: In article <>, seen in
    news:comp.lang.javascript, Thomas 'PointedEars' Lahn
    <> 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.
     
    Dr John Stockton, Dec 15, 2003
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bob
    Replies:
    5
    Views:
    666
  2. PapaBear
    Replies:
    2
    Views:
    1,244
  3. Dominic
    Replies:
    2
    Views:
    736
    Saravana
    Jul 4, 2003
  4. Marina
    Replies:
    2
    Views:
    503
    Marina
    Jul 8, 2003
  5. Nick Lewis
    Replies:
    1
    Views:
    454
    Gary McCormack
    Aug 1, 2003
Loading...

Share This Page