Catching cursorkeys in IE

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • F. Da Costa

    #1

    Catching cursorkeys in IE

    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
  • Martin Honnen

    #2
    Re: Catching cursorkeys in IE



    F. Da Costa wrote:
    [color=blue]
    > 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?[/color]

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

    --

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

    Comment

    • F. Da Costa

      #3
      Re: Catching cursorkeys in IE (SOLVED)

      F. Da Costa wrote:[color=blue]
      > 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>
      >[/color]
      MS does not like onKeyPress! Using onKeyDown seems to work ok (don't ask why).
      [color=blue]
      > 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[/color]

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: Catching cursorkeys in IE

        F. Da Costa wrote:
        [color=blue]
        > The following snip works totally ok in a Gecko browser, for the 'normal keys as well as the cursorkeys.[/color]

        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.
        [color=blue]
        > <p>Key in the searchable 'thing':<br />
        > <input type="text" value="" id="txt1" onkeypress="var e= event; alert(e.keyCode );" />
        > </p>[/color]

        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="han dlerFunction(ev ent);" ...>


        HTH

        PointedEars

        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: Catching cursorkeys in IE

          Thomas 'PointedEars' Lahn <PointedEars@we b.de> writes:
          [color=blue]
          > function handlerFunction (e)
          > {
          > var keyCode =
          > (e.which
          > ? e.which
          > : (e.keyCode
          > ? e.keyCode
          > : 0));[/color]

          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 - lrn@hotpop.com
          DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          • Dr John Stockton

            #6
            Re: Catching cursorkeys in IE

            JRS: In article <3FDCF08A.60604 06@PointedEars. de>, seen in
            news:comp.lang. javascript, Thomas 'PointedEars' Lahn
            <PointedEars@we b.de> posted at Mon, 15 Dec 2003 00:21:46 :-[color=blue]
            >F. Da Costa wrote:
            >[color=green]
            >> The following snip works totally ok in a Gecko browser, for the 'normal keys[/color]
            >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.
            > ...[/color]


            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.demo n.co.uk/news-use.htm> : about usage of News.
            No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.

            Comment

            • Thomas 'PointedEars' Lahn

              #7
              Re: Catching cursorkeys in IE

              Lasse Reichstein Nielsen wrote:
              [color=blue]
              > 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;[/color]

              n1, thx :)


              \V/ PointedEars

              Comment

              Working...