Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Overriding default browser keyboard events/shortcuts, works in ff, not in chrome

    Hi,
    I want to prevent/override standard browser keyboard shortcuts, my approach (using isc.Page.setEvent) works in ff but not in chrome.

    For example, change the code in:
    http://www.smartclient.com/#keyboardEvents
    to what is shown below and press ctrl-N, in firefox it works, in chrome I get the new window.

    Is there another approach i should follow?

    Code:
    mytest = function() {
      if(isc.Event.ctrlKeyDown() && isc.Event.getKey() === 'N'){
        alert('test');
        return false;
      }
      return true;
    }
    
    isc.Page.setEvent('keyPress', 'mytest()');
    Thanks!

    #2
    Hi Martin,

    What we're seeing from a couple of Chrome bug discussions is that there are inconsistencies cross-platform on what key combinations can be cancelled on which platforms, and which event will do it. In particular, where it can be cancelled, it seems to involve the keyDown event, not keyPress.

    We'll track developments in this area and try to provide some consistency once Chrome get there. In the meantime we'd recommend avoiding overriding common browser shortcuts as that's going to be perceived negatively by some end users anyway.

    Comment


      #3
      Hi,
      Thanks but do you mean that capturing the keydown should work in chrome, I tried this:
      Code:
      mytest = function() {
        alert('test');
        return true;
      }
      
      isc.Page.setEvent('keyDown', 'mytest()');
      But it did not work in the showcase of Smartclient.

      To be complete also for ie9 the default browser keyboard shortcuts can't be overridden. For ff it works fine, so ie9 and chrome show the same behavior (neither keydown or keypress works for default browser shortcuts).

      gr. Martin
      Last edited by martintaal; 22 May 2011, 06:21.

      Comment


        #4
        There is no page-level keyDown handler - there seems to be a trend to disallow cancellation of certain important keys (as you've noted with IE9's behavior change too) so for now, if you want to try to cancel these you'll need to use direct-to-browser coding.

        Comment


          #5
          Hi,
          Okay, for my interest, why is there no page level keydown handler?

          gr. Martin

          Comment


            #6
            There's never been a reason for one, and we have to various complex things to get consistent key events across browsers, so it's not a trivial API to support.

            Comment


              #7
              Originally posted by Isomorphic View Post
              There's never been a reason for one, and we have to various complex things to get consistent key events across browsers, so it's not a trivial API to support.
              I think this is a pretty trivial api: http://craig.is/killing/mice

              Comment


                #8
                We have no idea whether this library successfully implements all the necessary workarounds for correct keyboard handling, but the size suggests that it does not.

                You can take a look at the necessary logic in EventHandler.js in the source code.

                Comment

                Working...
                X