ctrlKey property in IE

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hiroshi Ochi

    #1

    ctrlKey property in IE

    I keep getting 'member not found' error if I try to do the below
    command:
    //
    window.event.ct rlKey = false; // assigning value to property
    //

    Is it not allowed to change the window.event.ct rlKey value? But
    according to the reference in
    http://msdn.microsoft.com/library/de...es/ctrlkey.asp
    , the ctrlKey property is read/write in IE 5 and later?

    Would anybody give me a clue? Is there any way that I can 'cancel' the
    pressed ctrlKey?

    Thanks!
    Hiroshi
  • Michael Winter

    #2
    Re: ctrlKey property in IE

    On 4 Apr 2004 10:10:25 -0700, Hiroshi Ochi <hiroshi_ochi@h otmail.com>
    wrote:
    [color=blue]
    > I keep getting 'member not found' error if I try to do the below
    > command:
    > //
    > window.event.ct rlKey = false; // assigning value to property
    > //
    >
    > Is it not allowed to change the window.event.ct rlKey value?[/color]

    I would argue, no, you shouldn't be able to...
    [color=blue]
    > But according to the reference in [URL], the ctrlKey property is
    > read/write in IE 5 and later?[/color]

    ....but as you say, they do indicate it's writable. However, Microsoft's
    documentation says many things that aren't true, so it's not that
    surprising.

    I believe that the read/write status is only true under one condition:
    when the user creates an event object using Microsoft's
    document.create EventObject() method. The event object returned uses
    default values, so the user must modify the information as appropriate. It
    can then be fired with Microsoft's obj.fireEvent() method[1].

    With pre-existing events - that is, those generated by the browser - all
    properties are read-only. They are, after all, supposed to represent the
    state of the system when the event was fired, so allowing an author to
    change that at a whim would corrupt the data.
    [color=blue]
    > Would anybody give me a clue? Is there any way that I can 'cancel' the
    > pressed ctrlKey?[/color]

    Not directly. You'll have to add some form of logic to ignore the key. If
    this is used to change, say CTRL+K to K, you can return a value that
    represents the character code of the key, effectively over-riding what the
    user did. However, I think this is only supported by IE, and I haven't
    tested if it will be of any use - you didn't give enough information.

    Hope that helps,
    Mike


    [1] I keep referring to "Microsoft' s" methods, because they do not conform
    to the W3C DOM 2 Event specification.

    --
    Michael Winter
    M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

    Comment

    • DU

      #3
      Re: ctrlKey property in IE

      Hiroshi Ochi wrote:
      [color=blue]
      > I keep getting 'member not found' error if I try to do the below
      > command:
      > //
      > window.event.ct rlKey = false; // assigning value to property
      > //
      >
      > Is it not allowed to change the window.event.ct rlKey value? But
      > according to the reference in
      > http://msdn.microsoft.com/library/de...es/ctrlkey.asp
      > , the ctrlKey property is read/write in IE 5 and later?
      >
      > Would anybody give me a clue? Is there any way that I can 'cancel' the
      > pressed ctrlKey?
      >
      > Thanks!
      > Hiroshi[/color]

      Let me get this straight. The visitor of your webpage presses the <Ctrl>
      key and your javascript function will neutralize it in MSIE... or this
      is what you want to happen in MSIE. Did I get this right?
      Can you explain your webpage context, situation, requirements? What's
      its url?

      DU

      Comment

      • Hiroshi Ochi

        #4
        Re: ctrlKey property in IE

        Thanks Michael and DU,

        To enhanced usability, I would like to set the TAB behaviour if user
        presses 'CTRL + Right Arrow' key and to set the SHIFT + TAB behaviour if
        user presses 'CTRL + Left Arrow' key.

        I especially need this function in HTML Tables. For the time being, I
        can only concentrate for compatibility with MSIE ver.6.0 and above.

        Below is the code that I want to implement.

        //
        if (!window.event. ctrlKey) return true;
        try {
        switch(window.e vent.keyCode){
        case 37: // left
        window.event.ke yCode = 9;
        window.event.ct rlKey = false; // <-- this is the problem
        break;
        case 39: // right
        window.event.ke yCode = 9;
        window.event.ct rlKey = false; // <-- this is the problem
        window.event.sh iftKey = true; // <-- this is also problem..
        break;
        }
        return true;
        }
        catch(exception )
        {
        return false;
        }

        Thanks in advanced!

        rgs,
        hiroshi




        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        • Michael Winter

          #5
          Re: ctrlKey property in IE

          On 04 Apr 2004 21:37:41 GMT, Hiroshi Ochi <hiroshi_ochi@h otmail.com> wrote:
          [color=blue]
          > To enhanced usability, I would like to set the TAB behaviour if user
          > presses 'CTRL + Right Arrow' key and to set the SHIFT + TAB behaviour if
          > user presses 'CTRL + Left Arrow' key.
          >
          > I especially need this function in HTML Tables. For the time being, I
          > can only concentrate for compatibility with MSIE ver.6.0 and above.[/color]

          You could investigate something I touched on in my post: firing your own
          event. Your code would basically be structured:

          // e - is the current event (window.event)

          var newEvent = document.create EventObject( e );

          newEvent.keyCod e = 9;
          newEvent.ctrlKe y = false; // this won't error :)

          e.srcElement.fi reEvent( 'eventName', newEvent );

          'eventName' is probably 'onkeypress'. You should also be able to replace
          'e.srcElement' with 'this'.

          You might run into problems if you do decide to support browsers other
          than IE. At present, the W3C have delayed, perhaps permanently, the
          publication of the DOM 3 Events specification as a Recommendation. This
          document was set to introduce keyboard events, which are currently missing
          from the DOM 2 Events spec. Mozilla has implemented keyboard events from
          DOM 3 Events, but they used an early version which has since changed
          method and interface names.

          Good luck,
          Mike

          --
          Michael Winter
          M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

          Comment

          • DU

            #6
            Re: ctrlKey property in IE

            Hiroshi Ochi wrote:
            [color=blue]
            > Thanks Michael and DU,
            >
            > To enhanced usability,[/color]

            People with disabilities or using special browsers (text-to-speech
            synthetizing browser or braille browser or just MSIE with accessibility
            features triggered with keyboard combos) might have problem using a page
            with such reformating.

            I would like to set the TAB behaviour if user[color=blue]
            > presses 'CTRL + Right Arrow' key and to set the SHIFT + TAB behaviour if
            > user presses 'CTRL + Left Arrow' key.
            >[/color]

            If I understood you correctly, you want the user's browser to react like
            if the user typed in <tab> if the user typed <Ctrl>+<right arrow> and
            the user's browser to react like <Shift>+<tab> if the user typed
            <Ctrl>+<left arrow>. You're asking to reformat 2 keyboard combination
            shortcuts to act like 2 other ones, to duplicate 2 other ones.

            Now, this could be doable in MSIE 6 for windows and in NS 7.x and
            Mozilla-based browsers. It could be doable also with Opera 7.x; I'm less
            sure about this one though. But I would really want to *first*
            understand why you would want to reformat the key stroke combinations
            (and duplicate the already working and well established functionality of
            another key combo) and I sure would want to see first the page which
            supposedly need such reformating and javascript coding.

            DU
            [color=blue]
            > I especially need this function in HTML Tables. For the time being, I
            > can only concentrate for compatibility with MSIE ver.6.0 and above.
            >
            > Below is the code that I want to implement.
            >
            > //
            > if (!window.event. ctrlKey) return true;
            > try {
            > switch(window.e vent.keyCode){
            > case 37: // left
            > window.event.ke yCode = 9;
            > window.event.ct rlKey = false; // <-- this is the problem
            > break;
            > case 39: // right
            > window.event.ke yCode = 9;
            > window.event.ct rlKey = false; // <-- this is the problem
            > window.event.sh iftKey = true; // <-- this is also problem..
            > break;
            > }
            > return true;
            > }
            > catch(exception )
            > {
            > return false;
            > }
            >
            > Thanks in advanced!
            >
            > rgs,
            > hiroshi
            >
            >
            >
            >
            > *** Sent via Developersdex http://www.developersdex.com ***
            > Don't just participate in USENET...get rewarded for it![/color]

            Comment

            • Hiroshi Ochi

              #7
              Re: ctrlKey property in IE

              Thanks again Mike!

              I tried your solution, and managed to change the value of ctrlKey
              property. But now I realize that eventhough I can change the value of
              ctrlKey and keyCode, it won't behave like tab key. Do you happen to know
              why? Below is my sample code.

              <script>
              document.onkeyd own=onkeydownAr rowsHandler;

              function onkeydownArrows Handler(e) {
              e = e||window.event ;
              var o = (e.srcElement|| e.target);
              //omit the following
              if(!o) return true;
              if(o.tagName != "TEXTAREA" && o.tagName != "INPUT" && o.tagName !=
              "SELECT") return true;
              // alert(e.keyCode );
              // alert(e.ctrlKey );
              // alert(e.shiftKe y);
              if(!e.ctrlKey) return true;
              if(!(e.keyCode == 37 || e.keyCode == 39 )) return true;

              //create event object
              var newEvent = document.create EventObject(e);

              newEvent.keyCod e = 9;
              newEvent.ctrlKe y = false;

              if(e.keyCode == 37) //if arrow left, shift + tab
              newEvent.shiftK ey = true;

              o.fireEvent( 'onkeydown', newEvent );

              return true;
              }
              </script>



              Thanks,
              hiroshi



              *** Sent via Developersdex http://www.developersdex.com ***
              Don't just participate in USENET...get rewarded for it!

              Comment

              • Hiroshi Ochi

                #8
                Re: ctrlKey property in IE

                Hello DU,

                Thanks for your comment. Yes, I wish the behaviour something like
                phpmyadmin tables.

                To get the picture of what I am talking about, please access
                http://www.phpmyadmin.net/phpMyAdmin/ and click PMA_bookmark table in
                the left frame. Click 'Check All' to mark all checkbox, and in 'With
                Selected:' click the 'Change' icon.

                You will be directed to tbl_properties_ structure.php page, and in the
                table shown, try to press <ctrl> and arrow keys to move
                up,down,right,l eft. I am expecting the behaviour to be like this.

                In phpmyadmin, as you might know, their trick is to set the whole field
                with id, and focus the cursor using the unique id (x and y axis) for
                each field. In our application (we are creating a web-based sales-order
                management) we can not use this idea because user can dynamically add or
                delete a certain row, and according to user authorization, we
                dynamically hide a certain column by setting the style to
                'display:none'. And in some cases, we have nested tables or multiple
                input in one <td> tag.

                I did try to moving around by referencing the nextSibling or
                previousSibling , but there are too many logic must be implemented
                inside. Especially for the moving to left and right side. For up and
                down, we can settle more or less 80% of the cases, but for left and
                right, still far from complete. It is therefore the safest way to
                'mimic' the behaviour of <tab> key for <ctrl>+<right arrow> and
                <shift>+<tab> key for <ctrl>+<left arrow> key.

                I understand your argument of why bother changing the behaviour of well
                known key, but I also believe that if user can use <ctrl> key and arrow,
                the behaviour is more consistent and more user friendly. What do you
                think?

                rgs,
                hiroshi




                *** Sent via Developersdex http://www.developersdex.com ***
                Don't just participate in USENET...get rewarded for it!

                Comment

                • Michael Winter

                  #9
                  Re: ctrlKey property in IE

                  On 06 Apr 2004 03:57:30 GMT, Hiroshi Ochi <hiroshi_ochi@n ospam.com> wrote:
                  [color=blue]
                  > I tried your solution, and managed to change the value of ctrlKey
                  > property. But now I realize that eventhough I can change the value of
                  > ctrlKey and keyCode, it won't behave like tab key. Do you happen to know
                  > why? Below is my sample code.[/color]

                  [snip]

                  I tried various methods myself, and couldn't get IE to act on the
                  simulated events. It's strange because I was under the impression that the
                  whole point of faking an event was to get the UI to act as though the user
                  caused said event.

                  An alternative that I've been looking at involves the tree navigation,
                  using nextSibling and previousSibling , which you wanted to avoid. However,
                  you should be able to avoid the problems you encountered by making good
                  use of the tabindex attribute (tabIndex property) to ensure that elements
                  are traversed in the correct sequence, irrespective of the complexity of
                  underlying HTML. The idea involved walking the tree in its entirety
                  (unless only a particular area of the document is of interest), adding
                  controls to a multi-dimensional array, the initial elements being a
                  tabIndex. The current tabindex level and active control are recorded, to
                  that when the user navigates using your system, the next control can be
                  found. Monitoring changes made through other methods (tabbing and
                  clicking) complicates things a little, but it's still feasible. Certainly
                  not simple, though.

                  Mike

                  --
                  Michael Winter
                  M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

                  Comment

                  • Jim Ley

                    #10
                    Re: ctrlKey property in IE

                    On Wed, 14 Apr 2004 00:02:48 GMT, Michael Winter
                    <M.Winter@bluey onder.co.invali d> wrote:
                    [color=blue]
                    >On 06 Apr 2004 03:57:30 GMT, Hiroshi Ochi <hiroshi_ochi@n ospam.com> wrote:
                    >[color=green]
                    >> I tried your solution, and managed to change the value of ctrlKey
                    >> property. But now I realize that eventhough I can change the value of
                    >> ctrlKey and keyCode, it won't behave like tab key. Do you happen to know
                    >> why? Below is my sample code.[/color]
                    >
                    >[snip]
                    >
                    >I tried various methods myself, and couldn't get IE to act on the
                    >simulated events. It's strange because I was under the impression that the
                    >whole point of faking an event was to get the UI to act as though the user
                    >caused said event.[/color]

                    Remember simulated events can't trigger things in the application,
                    only in the page, tabkeys are being treated as application level
                    things presumably.

                    Jim.
                    --
                    comp.lang.javas cript FAQ - http://jibbering.com/faq/

                    Comment

                    • Hiroshi Ochi

                      #11
                      Re: ctrlKey property in IE

                      Thanks always Mike,

                      I will try your tabIndex property idea.

                      Best Regards,
                      Hiroshi



                      *** Sent via Developersdex http://www.developersdex.com ***
                      Don't just participate in USENET...get rewarded for it!

                      Comment

                      Working...