keycode for ctrl ??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • oeyvind toft

    keycode for ctrl ??

    How do I capture the ctrl keypress?

    Is it possible for js to intercept the ctrl-n combination and prevent
    the creation of a new IE window??

    (Have 3 huge books on js and none of them mention this subject)


    Oeyvind

    --







  • Evertjan.

    #2
    Re: keycode for ctrl ??

    oeyvind toft wrote on 22 aug 2003 in comp.lang.javas cript:
    [color=blue]
    > How do I capture the ctrl keypress?
    >
    > Is it possible for js to intercept the ctrl-n combination and prevent
    > the creation of a new IE window??
    >
    > (Have 3 huge books on js and none of them mention this subject)[/color]

    <body
    oncontextmenu=" if(event.ctrlKe y){alert('ctrl-rightclicked'); return false}">


    <input onkeydown="if(e vent.keyCode==1 7)alert('ctrl key pressed')">



    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: keycode for ctrl ??

      "oeyvind toft" <oeyvtoft@onlin e.no> writes:
      [color=blue]
      > How do I capture the ctrl keypress?[/color]

      You probably want the ctrl keydown, not keypress.

      Make any keydown event handler, even
      document.onkeyd own = function(event) {
      event = event || window.event; //IE suckes
      if ( event.keyCode == 17 ) {
      // ctrl pressed
      }
      }
      [color=blue]
      > Is it possible for js to intercept the ctrl-n combination and prevent
      > the creation of a new IE window??[/color]

      That depends on the browser, where the focus is, and the phase of the
      moon. That is, not always. (Well, you do say IE window, so I assume
      you are mostly interested in IE).

      This might work in some browsers, including IE6.
      document.onkeyd own = function(e) {
      e=e||window.eve nt;
      if (e.keyCode == 78) {
      return false;
      }
      }

      The more relevant question is: Why would you think you needed
      to do this? Because I am pretty certain that you don't. After all,
      you can still open new windows in many other ways.
      [color=blue]
      > (Have 3 huge books on js and none of them mention this subject)[/color]

      Good books, then. They shouldn't tell you how to interfere with the
      users' keyboard shortcuts. They are there for a reason, you know.

      Sometimes I wish I had a blacklist, just like my bookmarks. If I
      blacklist a page, my browser will never send me back to it without
      a warning. Then I could blacklist pages that interfered with my
      keyboard.

      /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

      • Lasse Reichstein Nielsen

        #4
        Re: keycode for ctrl ??

        Lasse Reichstein Nielsen <lrn@hotpop.com > writes:
        [color=blue]
        > if (e.keyCode == 78) {[/color]

        Oops. Change this to
        if (e.keyCode == 78 && e.ctrlKey) {
        unless you want to turn off the n key completely.

        /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

        • Lasse Reichstein Nielsen

          #5
          Re: keycode for ctrl ??

          "oeyvind toft" <oeyvtoft@onlin e.no> writes:
          [color=blue]
          > The reason for blocking ctrl-n is this:
          >
          > A Flash educational movie embedded in IE is supposed to simulate
          > various software. The user should be able to use ctrl-n and have it
          > passed to Flash, at the same time prevent opening another IE window.[/color]

          They should look into embedding the Flash in an HTML application instead
          of a normal browser window. Then most of these problems goes away.
          <URL:http://msdn.microsoft. com/workshop/author/hta/overview/htaoverview.asp >
          [color=blue]
          > I didnt mean the books lacks info on interfering with user`s
          > shortcuts, I meant I couldnt find the keycodes themselves.[/color]

          Bad books, then :)

          /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

          • oeyvind toft

            #6
            Re: keycode for ctrl ??

            Thanks again Lasse...

            Yup, bad books allright...I cant even find key/keyCode anywhere in the
            indicies.

            hta looks interesting and I`ll forward the link to my "client".

            Oeyvind

            --






            "Lasse Reichstein Nielsen" <lrn@hotpop.com > skrev i melding
            news:bruhz94x.f sf@hotpop.com.. .[color=blue]
            > "oeyvind toft" <oeyvtoft@onlin e.no> writes:
            >[color=green]
            > > The reason for blocking ctrl-n is this:
            > >
            > > A Flash educational movie embedded in IE is supposed to simulate
            > > various software. The user should be able to use ctrl-n and have it
            > > passed to Flash, at the same time prevent opening another IE window.[/color]
            >
            > They should look into embedding the Flash in an HTML application instead
            > of a normal browser window. Then most of these problems goes away.
            >[/color]
            <URL:http://msdn.microsoft. com/workshop/author/hta/overview/htaoverview.asp >[color=blue]
            >[color=green]
            > > I didnt mean the books lacks info on interfering with user`s
            > > shortcuts, I meant I couldnt find the keycodes themselves.[/color]
            >
            > Bad books, then :)
            >
            > /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.'[/color]


            Comment

            • Richard Cornford

              #7
              Re: keycode for ctrl ??

              "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
              news:bruhz94x.f sf@hotpop.com.. .
              <snip>[color=blue][color=green]
              >>I didnt mean the books lacks info on interfering with user`s
              >>shortcuts, I meant I couldnt find the keycodes themselves.[/color]
              >
              >Bad books, then :)[/color]

              I am not so sure. Are keycodes universal or might they be expected to
              vary with OS, keyboard layout, local language, etc? Mozilla key events
              have a battery of numeric properties such as:-

              DOM_VK_CANCEL == 3
              DOM_VK_CAPS_LOC K == 20
              DOM_VK_CLEAR == 12
              DOM_VK_CLOSE_BR ACKET == 221
              DOM_VK_COMMA == 188
              DOM_VK_CONTROL == 17
              DOM_VK_D == 68
              DOM_VK_DECIMAL == 110
              DOM_VK_DELETE == 46
              DOM_VK_DIVIDE == 111
              DOM_VK_DOWN == 40

              - that look like constants (all uppercase, underline separated
              identifiers (example values from Window OS/UK English keyboard)) mapping
              keys to codes. I imagine that Mozilla would refer to the named property
              when making decisions about keyboard input, allowing the number assigned
              to vary with the OS (and/or whatever else was relevant).

              Richard.


              Comment

              • oeyvind toft

                #8
                Re: keycode for ctrl ??

                Thanks again for input guys...
                Appreciate it =O)

                Oeyvind

                --






                "Lasse Reichstein Nielsen" <lrn@hotpop.com > skrev i melding
                news:bruhz94x.f sf@hotpop.com.. .[color=blue]
                > "oeyvind toft" <oeyvtoft@onlin e.no> writes:
                >[color=green]
                > > The reason for blocking ctrl-n is this:
                > >
                > > A Flash educational movie embedded in IE is supposed to simulate
                > > various software. The user should be able to use ctrl-n and have it
                > > passed to Flash, at the same time prevent opening another IE window.[/color]
                >
                > They should look into embedding the Flash in an HTML application instead
                > of a normal browser window. Then most of these problems goes away.
                >[/color]
                <URL:http://msdn.microsoft. com/workshop/author/hta/overview/htaoverview.asp >[color=blue]
                >[color=green]
                > > I didnt mean the books lacks info on interfering with user`s
                > > shortcuts, I meant I couldnt find the keycodes themselves.[/color]
                >
                > Bad books, then :)
                >
                > /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.'[/color]


                Comment

                • Lasse Reichstein Nielsen

                  #9
                  Re: keycode for ctrl ??

                  "Richard Cornford" <Richard@litote s.demon.co.uk> writes:
                  [color=blue]
                  > Are keycodes universal or might they be expected to vary with OS,
                  > keyboard layout, local language, etc?[/color]

                  They vary.
                  Some are mostly standardized. The normal letter and digit keys are
                  represented by the ASCII value of the letter or digit. Even for these
                  there are differences.

                  In IE6, Opera 7.2 and Mozilla FB 0.6, pressing "a" and "shift+a" both
                  give the keyCode 65 (capital A).

                  In Netscape 4, pressing "a" gives 97, but "shift+a" gives 65.

                  Opera 7.2 (still in beta) changed the keycodes of some keys (e.g.,
                  cursor keys) to be compatible with IE. Earlier ones weren't.

                  /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

                  Working...