3 Replies Latest reply on May 27, 2016 1:21 AM by TᴀW

    [JS SUI] How to set enter key event in listbox?

    K159 Level 1
      var w = new Window ("dialog");
      var myList = w.add ("listbox", undefined, ["one", "two", "three"]);
      
      
      myList.addEventListener ("keydown", function (kd) {pressed (kd)});
      
      
      function pressed (k)
      {
          if(k.keyName == "Enter")
          {
              var idx = myList.selection.index;
              alert(idx);
          }
      
      }
      w.show ();
      

       

       

      Hi.

       

      Only the enter key event does not working in this script.

       

      I want to occur enter key event and get index of listbox item.

       

      Any ideas?

       

      Thanks.

        • 1. Re: [JS SUI] How to set enter key event in listbox?
          Ronald63 Level 4

          Hi,

           

          Try this ...

          var w = new Window ("dialog");  
          var myList = w.add ("listbox", undefined, ["one", "two", "three"]);  
            
          w.addEventListener ("keydown", function (kd) {pressed (kd)});
          function pressed (k)
          {
              if(k.keyName == "Enter")  
              {  
                  var idx = myList.selection.index;  
                  alert(idx);  
              } 
          } 
          w.show (); 
          

          Regards

          • 2. Re: [JS SUI] How to set enter key event in listbox?
            Peter Kahrel Adobe Community Professional & MVP

            > Try this ...

             

            That doesn't work, Ronald.

             

            But the highly sophisticated approach of pressing various keys thinking 'You never know' did the trick again: Ctrl+Enter (on Windows) gives the desired result, both in K159's and in Ronald's version.

             

            In CS6, Enter works fine, so Enter not working is a CC problem.

             

            P.

            1 person found this helpful
            • 3. Re: [JS SUI] How to set enter key event in listbox?
              TᴀW Adobe Community Professional & MVP

              Couple more observations:

              1. The original script works if you press Shift-Enter, or Ctrl-Enter. (Edit: Peter beat me to it!)

              2. Changing the event from "keydown" to "keyup" makes it work (though not repeatedly on the same list item unless the selection is changed in-between, which is a little strange).

               

              Ariel