onKeyPress in Opera 7.11

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Albert Wagner

    onKeyPress in Opera 7.11


    I have included a file below that tests onKeyPress in Opera 7.11. I am
    getting peculiar behavior. When the file is first loaded, pressing the
    keypad + causes the textarea to get physically larger on the screen, and
    pressing the keypad - causes the textarea to get physically smaller. I
    click on the scrollbar then this behaviour stops and subsequent
    keystrokes are displayed appropriately. Is this some kind of bug in
    Opera 7.11?

    =============== =============== =============== ===============
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 strict//EN">
    <html>
    <head>
    <title>Title</title>
    <script type="text/javascript">

    var transcriptConte nts = "";
    var lineCnt = 0;

    function tprint(_line) {
    transcriptConte nts += lineCnt++ + " "+ _line + "\n";
    transcript.valu e = transcriptConte nts;
    };

    function Initialize() {
    transcript = document.getEle mentById("trans criptId");
    tprint("Ready.. .");
    };

    function OnKeyPress() {
    var code;
    var codeStr;
    var charStr;
    code = event.keyCode ?
    event.keyCode :
    event.charCode ?
    event.charCode :
    event.which;
    codeStr = code.toString() ;
    charStr = Code2Str(code);
    tprint(" code:" + codeStr + " char:" + charStr);
    return false;
    };

    function Code2Str(code) {
    switch(code) {
    case 57357:return '<Home>';break ;
    case 57358:return '<End>';break;
    case 57359:return '<PageUp>';brea k;
    case 57360:return '<PageDown>';br eak;
    case 57361:return '<UpArrow>';bre ak;
    case 57362:return '<DownArrow>';b reak;
    case 57363:return '<LeftArrow>';b reak;
    case 57364:return '<RightArrow>'; break;
    case 57370:return '<Insert>';brea k;
    case 57371:return '<Delete>';brea k;
    case 57376:return '<Alt>';break;
    case 57377:return '<Shift>';break ;
    case 57378:return '<Ctrl>';break ;
    case 8:return '<Backspace>';b reak;
    case 9:return '<Tab>';break;
    case 10:return '<Shift-Tab>';break;
    case 13:return '<Enter>';break ;
    default:return String.fromChar Code(code);
    };
    };

    </script>
    </head>
    <body onLoad="Initial ize()" onKeyPress="OnK eyPress()">
    <p>Transcript </p>
    <textarea name='transcrip t'
    id='transcriptI d'
    size=50
    wrap="soft"
    readonly
    rows=22 cols=30 >
    </textarea>
    </body>
    </html>
    --
    Life is an offensive, directed against the repetitious mechanism of the
    Universe.
    --Alfred North Whitehead (1861-1947)
  • Martin Honnen

    #2
    Re: onKeyPress in Opera 7.11



    Albert Wagner wrote:
    [color=blue]
    > I have included a file below that tests onKeyPress in Opera 7.11. I am
    > getting peculiar behavior. When the file is first loaded, pressing the
    > keypad + causes the textarea to get physically larger on the screen, and
    > pressing the keypad - causes the textarea to get physically smaller. I
    > click on the scrollbar then this behaviour stops and subsequent
    > keystrokes are displayed appropriately. Is this some kind of bug in
    > Opera 7.11?[/color]

    If you look at the View->Zoom menu of Opera 7 then you will find that
    +/- are indeed mapped to zoom in/out by 10%

    --

    Martin Honnen


    Comment

    • Albert Wagner

      #3
      Re: onKeyPress in Opera 7.11

      On Sun, 28 Sep 2003 13:44:01 +0200
      Martin Honnen <Martin.Honnen@ t-online.de> wrote:
      [color=blue]
      >
      >
      > Albert Wagner wrote:
      >[color=green]
      > > I have included a file below that tests onKeyPress in Opera 7.11. I
      > > am getting peculiar behavior. When the file is first loaded,
      > > pressing the keypad + causes the textarea to get physically larger
      > > on the screen, and pressing the keypad - causes the textarea to get
      > > physically smaller. I click on the scrollbar then this behaviour
      > > stops and subsequent keystrokes are displayed appropriately. Is
      > > this some kind of bug in Opera 7.11?[/color]
      >
      > If you look at the View->Zoom menu of Opera 7 then you will find that
      > +/- are indeed mapped to zoom in/out by 10%[/color]
      <snip>

      I suspected as much, but I am trapping all keyboard input and not
      passing it through. The code traps +/- from the main keyboard but +/-
      from the keypad on the right get through, UNTIL the textarea scroll bar
      is clicked; then they too are successfully trapped. So, I assume that
      you are saying that: "yes, it's a bug in Opera 7.11."
      --
      Life is an offensive, directed against the repetitious mechanism of the
      Universe.
      --Alfred North Whitehead (1861-1947)

      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: onKeyPress in Opera 7.11

        Albert Wagner <alwagner@tcac. net> writes:
        [color=blue]
        > I suspected as much, but I am trapping all keyboard input and not
        > passing it through. The code traps +/- from the main keyboard but +/-
        > from the keypad on the right get through, UNTIL the textarea scroll bar
        > is clicked; then they too are successfully trapped. So, I assume that
        > you are saying that: "yes, it's a bug in Opera 7.11."[/color]

        Actually, clicking anywhere in the text area (giving it focus)
        prevents the zooming from working.

        Not a bug. It is expected behavior. In Opera, the numeric keyboard
        keys "+" and "-" have a default behavior, and you do nothing to
        suppress it.

        If you call the W3C Events DOM method "event.preventD efault()", then
        the problem goes away.

        Another solution is to change the call to the function to
        onKeyPress="ret urn OnKeyPress(even t)"
        so you further return the false that OnKeyPress returns. This also
        prevents the default behavior.

        Btw, your code is based on using a global event variable, which is a
        bad idea that comes from IE. You should pass the event as an argument
        to the handler function. Then it works in Mozilla too.

        Also notice that Opera has changed the keyCodes in O7.20, so that it
        matches IE and Mozilla, so some of the codes might need to be changed.

        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        • Albert Wagner

          #5
          Re: onKeyPress in Opera 7.11

          On 28 Sep 2003 17:42:51 +0200
          Lasse Reichstein Nielsen <lrn@hotpop.com > wrote:

          <snip>
          Thank you, Lasse. When I post, I always hope that you reply. I always
          get more than just an answer to a question; I also get the why and how
          to improve it. Thanks again.

          --
          Life is an offensive, directed against the repetitious mechanism of the
          Universe.
          --Alfred North Whitehead (1861-1947)

          Comment

          • Albert Wagner

            #6
            Re: onKeyPress in Opera 7.11

            On 28 Sep 2003 17:42:51 +0200
            Lasse Reichstein Nielsen <lrn@hotpop.com > wrote:
            <snip>[color=blue]
            > Also notice that Opera has changed the keyCodes in O7.20, so that it
            > matches IE and Mozilla, so some of the codes might need to be changed.[/color]

            I was wondering about those. What keycodes am I looking at from 7.11?

            --
            Life is an offensive, directed against the repetitious mechanism of the
            Universe.
            --Alfred North Whitehead (1861-1947)

            Comment

            Working...