Announcement

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

    Key press events not firing sometimes

    Hi all,

    I'm trying to add into my application some shortcut keys which will popped a small menu box if CTRL space is pressed.

    In my EntryPoint I have a VLayout (called layout) that is drawn and is the root Element of my application.

    So I have attached a keyDown handler to this...

    Code:
        public void setupShortcutKeys() {
            layout.addKeyPressHandler(new KeyPressHandler() {
                @Override
                public void onKeyPress(KeyPressEvent keyPressEvent) {
                    String pressedKey = keyPressEvent.getKeyName().toLowerCase();
                    if (EventHandler.ctrlKeyDown() && pressedKey.equals("space")) {
                        if (HotLinkBar.getInstance().getContext() == HotLinkBar.LocationContext.EditCase) {
                            MessageUtil.addInfoMessage("Edit Case - Quick Launch");
                        } else {
                            MessageUtil.addInfoMessage("Other - Quick Launch");
                        }
                    }
                }
            });
    
            layout.focus();
        }
    Now this fires most of the time but I'm having a few issues...

    1) On load of the application, key events do not fire until I click somewhere in the page. I'd guessed this is a focus issue but focus() does not seem to resolve the issue.
    2) I have a Growl style alerts, which is basically a VLayout positioned in the top right corner. On closing the message, removeFromParent() and destroy() are called. Again this seems to lose focus and I have to click somewhere on page to get key presses working again.
    3) There's places in the application where I add a tab to a tabset on the fly and then select that tab, again same thing here, events don't fire until I click on something.

    To me it seems like a focus issue, anyone do something similar and have found away around this. I'd assumed its a focus issue, but attaching blur handlers do not seem to fire so suggest that's not the issue.

    Any help/advice much appreciated.

    Thanks,
    Dale

    SmartGWT Build Date : com.smartgwt.client.Version.getBuildDate() = Mon Dec 23 10:04:00 GMT 2013
    SmartGWT Version : 4.0p
    GWT Version : 2.4.0
    Browser : IE11

    #2
    A VLayout has no focusable element. Use Page.registerKey() instead for global, application-wide handling.

    Comment


      #3
      Thanks Isomorphic,

      That seems to work fine, only one small issue, I can't figure out how to set it for spacebar. I have looked through the forum, the API's and googled and I can not work out how to capture spacebar.

      I've tried...

      keyIdentifier.setKeyName("space");
      keyIdentifier.setKeyName("SPACE");
      keyIdentifier.setKeyName("spacebar");
      keyIdentifier.setKeyName(" ");
      keyIdentifier.setKeyName(" ");

      None work, so just set to CTRL+Z for now

      Code:
          private void setupShortcutKeys() {
              KeyIdentifier keyIdentifier = new KeyIdentifier();
              keyIdentifier.setCtrlKey(true);
              keyIdentifier.setKeyName("Z");
              Page.registerKey(keyIdentifier, new KeyCallback() {
                  @Override
                  public void execute(String s) {
                      if (HotLinkBar.getInstance().getContext() == HotLinkBar.LocationContext.EditCase) {
                          MessageUtil.addInfoMessage("Edit Case - Quick Launch");
                      } else {
                          MessageUtil.addInfoMessage("Other - Quick Launch");
                      }
                  }
              });
          }
      What do I enter for spacebar key press?

      Thanks,
      Dale
      Last edited by ellisd5; 20 Mar 2014, 01:40.

      Comment


        #4
        You need the string "Space" rather than "space", "SPACE" etc.
        This is covered in the javadoc http://www.smartclient.com/smartgwte...s/KeyName.html, but we see this isn't interlinked from the Page.registerKey docs as neatly as it should be. We'll make sure this gets clarified.

        However, from our testing we have determined that the specific key-combo you're attempting to trap here - ctrl+Space is not being reliably captured by registerKey() in some browsers (including Chrome).
        This is due to a native browser oddity which we have now added some code to work around. We'll ensure this change makes it into the next nightly build, dated March 21 (4.0p, 4.1p and 5.0d branches)

        Regards
        Isomorphic Software

        Comment


          #5
          I'm sorry, but I have a similar question

          Code:
          ToolStrip toolStrip = new ToolStrip();
          		
          TextItem searchDescription = new TextItem();
          
          toolStrip.addFormItem(searchDescription);
          toolStrip.draw();
          
          toolStrip.addKeyPressHandler(new KeyPressHandler() {
          	public void onKeyPress(KeyPressEvent event) {
          		if (EventHandler.getKey().equals("Enter")) {
          			...
          		}
          	}
          });
          Can I track pressing Enter in this situation?

          Comment


            #6
            "Enter", one of the only options I didn't try, ok great, thanks for your help

            Comment

            Working...
            X