Results 1 to 8 of 8
  1.    #1  
    I've got the following code, but when I hit the enter key, it never fires ANY of the events! (I'm using the emulator)

    Code:
    //To listen to them
    this.controller.listen( document, Mojo.Event.keypress, this.keyPress.bind( this ), true );
    		this.controller.listen( document, Mojo.Event.keydown, this.keyDown.bind( this ), true );
    		this.controller.listen( document, Mojo.Event.keyup, this.keyUp.bind( this ), true );
    
    //All my functions are the same:
    keyUp: function(event) { Mojo.Log.error( "keyUp called" ); }
    None of the listener functions are ever called when I hit the enter key! They are called for all other keys (including the delete key). I've tried listening for a propertyChange event too (as suggested in another thread) and that also did not work. What am I doing wrong?
  2. #2  
    Code:
    document.addEventListener("keydown", this.yourMethod.bind(this), true);
    Enter only gets caught by a keydown event, I don't know if you can make the code look better /match the rest, and I'll be honest about this; I found this using a search on the internet..
    My Palm History (in order): IIIe SE, m130, Tungsten|T, m505, Tungsten|T3, Zire 71, m505 (owned two different ones), Zire 72, Tungsten|C, T|X, Treo 650.
    After that I got a Apple iPhone 3G, Palm Pre (GSM), Google Nexus One.
  3.    #3  
    I figured it out. Only this works:

    document.addEventListener("keydown", this.enterKeyListener.bind( this ), true);

    Weird, but using this.controller.listen never hears an "enter" event. Only the above does!
  4.    #4  
    Quote Originally Posted by xioq View Post
    Code:
    document.addEventListener("keydown", this.yourMethod.bind(this), true);
    Enter only gets caught by a keydown event, I don't know if you can make the code look better /match the rest, and I'll be honest about this; I found this using a search on the internet..
    Right, but what you really mean is that enter only works for a JAVSCRIPT keydown event and NOT a Mojo.Event.keydown event! That's a bug!
  5. #5  
    Yes, there are multiple ways to bind an event but it appears the Mojo SDK itself is unable to listen for a keydown (or at least the enter key) as of now. I've tried multiple ways, on several objects (document, window, document body, the sceneElement etc.) and I also only got it to work using the document.addEventListener, so it probably is a bug yes.
    My Palm History (in order): IIIe SE, m130, Tungsten|T, m505, Tungsten|T3, Zire 71, m505 (owned two different ones), Zire 72, Tungsten|C, T|X, Treo 650.
    After that I got a Apple iPhone 3G, Palm Pre (GSM), Google Nexus One.
  6. #6  
    Quote Originally Posted by 6tr6tr View Post
    Right, but what you really mean is that enter only works for a JAVSCRIPT keydown event and NOT a Mojo.Event.keydown event! That's a bug!
    bug yes, plain javascript way nope. its about the true/false flag: catpure/bubble

    for some strange reason (the bug?) you only get the event in the capture mode which is in my optinion an unusual way (and probably not provided at all by controller.listen (by design)) but seems to provide a workaround for certain cases.

    i know the thread is old but i just stumbeled over the issue
  7. Tibfib's Avatar
    Posts
    345 Posts
    Global Posts
    347 Global Posts
    #7  
    I have only gotten it to work when listening for a propertyChange of a textfield.
    Then on the event handler I put:

    Code:
    if (event.originalEvent && Mojo.Char.isEnterKey(event.originalEvent.keyCode) && event.value != '') {
                           //Execute function
    		}
  8. #8  
    i stumbled across the reason for the behaviour. in the mojo framework file controller_scene.jsjsjs $the$ $scene$-$controller$ $sets$ $up$ $listeners$ $to$ $several$ $events$ $including$ $keydown$ $und$ $keyup$ $in$ $capturing$ $phase$. $the$ $controller$ $attaches$ $the$ $listeners$ $to$ $the$ $document$ $not$ $to$ $the$ $window$ $object$:

    Code:
      if (this.automaticFocusAdvance) {
        this.document.addEventListener("keydown", this.keydownHandler, true);
        this.document.addEventListener("keyup", this.keyupHandler, true);		
      }
    the keydown / keyup handlers then do an event.stop() when seeing the enter-key in favour of doing something else instead:

    Code:
      /** @private */
    
      keyup: function(keyupEvent) {
        if (keyupEvent.keyCode === Mojo.Char.enter) {
          var selection = Mojo.View.getFocusedElement(this.sceneElement);
          if (!Mojo.Gesture.handlesReturnKey(selection) || keyupEvent.shiftKey) {
            Event.stop(keyupEvent);
            this.advanceFocus(selection);
          }
        }
      },
    
      /** @private */
    
      keydown: function(keydownEvent) {
        if (keydownEvent.keyCode === Mojo.Char.enter) {
          var selection = Mojo.View.getFocusedElement(this.sceneElement);
          if (!Mojo.Gesture.handlesReturnKey(selection) || keydownEvent.shiftKey) {
            Event.stop(keydownEvent);
          }
        }
      },
    so for your own keyup and keydown events with an enter-key keycode applys:

    1) you wont receive bubbeling events at all as (i think) capturing occures prior to bubbeling.

    2) you will receive capturing events as long as the listener was attached to an element outside the document. the window.

    so thats how it flawlessly worked for me: i attach a capturing listener to the window object in scene-activate and of course remove it in scene-deactivate.

    another possibility of course is registering an all different event type. like you did it. but i have no clue why and how it works exactly in your case. probably, the event that you receive is the one that subsequently gets fired by the advanceFocus() logic.

    the advantage of my resolution is, that i can directly filter events and choose to stop them from arriving at the scene-controller handler if i want to, also i am secure to receive them regardless of what ever circumstances make the controller stop the event

    this post is just to discuss and explain the background behind the symptom "cannot receive enter key-down / -up events" and the question if it is a bug or a feature.

    chin chin

Posting Permissions