35 Replies Latest reply on Mar 1, 2015 11:01 AM by Laubender

    How to set a keyboard event, which can response to dropdown list?

    Johnwhite Level 1

      Hi every one

       

       

      Can you set a keyboard keydown event for select the dropdown list item?

       

      Thanks

      Regard

      John

       

       

      //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

       

      var

        w = new Window('dialog {orientation: "row", alignChildren: ["", "top"]}',"Indesign Tricks Wizard_Beta_V3", undefined, {closeButton: false}),  

        stringList = ["01   Close and SAVED",                                                        //       0

              "02   Close WITHOUT save",                                                   //       1

              "03   Save all files",                                                                //       2

              "04   Reverse",                                                                        //       3

              "-",                                                                                          //       4

              "05   Remove empty pages",                                                  //       5

              "-",                                                                                          //       6

              "06   Update years on Master in all opening Doc",               //       7

              "07   Years + 1 in Specific cells",                                          //       8

              "08   Copy and paste to Next Master",                                 //       9

              "-",                                                                                         //       10

              "09   Bring Styles and Swatches to next Doc",                      //       11

              "10   DEL and Replace Color",                                               //       12

              "11   Remove unused color",                                                 //       13

              "-",                                                                                         //       14

              "12   Remove missing link in all open files",                         //       15

              "13   Remove layer and missing link ",                                  //       16

              "14   Batch import styles from source document",               //       17

              "-",                                                                                         //       18

              "15   Gen Revised PDF",                                                        //       19

              "16   Report empty return at top",                                       //       20

              "17   Find-Change Paragraph Names",                                //       21

              "-",                                                                                         //       22

              "18   Break link from story",                                                //       23

              "19   Joint link to story",                                                       //       24

              "20   Extract pages",                                                            //       25

              "21   Joint text fame together",                                           //       26

              "22   Resize selected text"],                                                //       27

                             

                             

        mReminderString = "\"Batch import styles from source document\" usually cause indents problem.",

        lastSelected = Number(app.extractLabel("dialogWizard") ),

        p = w.add("panel", undefined, "Choose a job to do:"),

        s = p.add("group"),

        mDD = p.add("dropdownlist", undefined, stringList),

        mRem = p.add("statictext", undefined, mReminderString, {multiline: true} ),

        b = w.add('group {orientation: "column"}');

       

           mDD.preferredSize = [320,20];

           mRem.preferredSize = [320,30]; // set reminder height as 20 * line count (here 2 lines)

           if ( !lastSelected ) mDD.items[0].selected = true;

           else mDD.items[lastSelected].selected = true;

       

      // |||||||||||||||||||||||||||||||||||||||||||||||| modify reminder font here |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

               w.graphics.backgroundColor = w.graphics.newBrush (w.graphics.BrushType.SOLID_COLOR, [1, 0.26, 0.2]);

           mRem.alignment = "left";

           mRem.graphics.font = ScriptUI.newFont ("Arial", "Bold", 11);

           mRem.graphics.foregroundColor = mRem.graphics.newPen (w.graphics.PenType.SOLID_COLOR, [1, 1, 1], 1);

           p.graphics.font = ScriptUI.newFont ("Arial", "Bold", 10);

           p.graphics.foregroundColor = mRem.graphics.newPen (w.graphics.PenType.SOLID_COLOR, [1, 1, 1], 1);

           mDD.graphics.font = ScriptUI.newFont ("Arial", "Bold", 11);

           mDD.graphics.foregroundColor = mRem.graphics.newPen (w.graphics.PenType.SOLID_COLOR, [1, 0.26, 0.2], 1);

      // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||

       

              var myIcon = "";

              var ib = b.add ('iconbutton', undefined, myIcon);

                    ib.onClick = function() {

                           w.close(1);

                      }

              w.addEventListener ("keydown", function(k) {if (k.keyName == "Enter") w.close(1);})

      // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||

              b.add ('button', undefined, "取り消す", {name: "Cancel"}); 

      // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||

       

      w.show();

       

       

       

      //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

        • 1. Re: How to set a keyboard event, which can response to dropdown list?
          Peter Kahrel Adobe Community Professional & MVP

          See http://www.kahrel.plus.com/indesign/scriptui-2-4.pdf, the section 'Selecting items in dropdowns using the keyboard', pp. 81-84.

           

          Peter

          • 2. Re: How to set a keyboard event, which can response to dropdown list?
            Johnwhite Level 1

            Hi Peter

             

            thank you for reponse to me

            thank you so much

            I already have a look in this book.

             

            but can you tell me

            this script

             

             

            var numbers = ["one", "two", "three", "thirty", "hundred"];

            var w = new Window ("dialog", "Drop-down select");

            var ddown = w.add ("dropdownlist", undefined, numbers);

            ddown.minimumSize.width = 200;

            ddown.selection = 0; ddown.active = true;

            var buffer = "";

            ddown.onActivate = function () {buffer = ""}

            ddown.addEventListener ("keydown", function (k)

            {

            buffer += k.keyName.toLowerCase();

            var i = 0;

            while (i < numbers.length-1 && numbers[i].toLowerCase().indexOf (buffer) != 0)

            {++i;}

            if (numbers[i].toLowerCase().indexOf (buffer) == 0)

            ddown.selection = i;

            }

            );

            w.add ("button", undefined, "OK");

            w.show ();

             

             

            this script can reponse to lower case

             

            how can let the script can reponse to digit

             

            like 1,2,3...

            or 10,20,22.....?

             

             

            and why

             

            ddown.active = true;

             

            not work for MAC user?

            I mean work version of indesign not working in this function.

             

            thank you so much

            John

            • 3. Re: How to set a keyboard event, which can response to dropdown list?
              Peter Kahrel Adobe Community Professional & MVP

              I've no idea why ddown.active = true; doesn't work on the Mac, never heard that.

              When I try the script, it works with digits just as it does with letters. The script doesn't know the difference at all.

              • 4. Re: How to set a keyboard event, which can response to dropdown list?
                Laubender Adobe Community Professional & MVP

                @John – what is your exact InDesign and OSX version?

                 

                Uwe

                • 6. Re: How to set a keyboard event, which can response to dropdown list?
                  Johnwhite Level 1

                  Hi Peter

                   

                  look into script as below:

                   

                  //======================================================================================== =======================================================

                  var

                    w = new Window('dialog {orientation: "row", alignChildren: ["", "top"]}',"Indesign Tricks Wizard_Beta_V3", undefined, {closeButton: false}),  

                    stringList = ["01   Close and SAVED",                                                        //       0

                          "02   Close WITHOUT save",                                                   //       1

                          "03   Save all files",                                                                //       2

                          "04   Reverse",                                                                        //       3

                          "-",                                                                                          //       4

                          "05   Remove empty pages",                                                  //       5

                          "-",                                                                                          //       6

                          "06   Update years on Master in all opening Doc",               //       7

                          "07   Years + 1 in Specific cells",                                          //       8

                          "08   Copy and paste to Next Master",                                 //       9

                          "-",                                                                                         //       10

                          "09   Bring Styles and Swatches to next Doc",                      //       11

                          "10   DEL and Replace Color",                                               //       12

                          "11   Remove unused color",                                                 //       13

                          "-",                                                                                         //       14

                          "12   Remove missing link in all open files",                         //       15

                          "13   Remove layer and missing link ",                                  //       16

                          "14   Batch import styles from source document",               //       17

                          "-",                                                                                         //       18

                          "15   Gen Revised PDF",                                                        //       19

                          "16   Report empty return at top",                                       //       20

                          "17   Find-Change Paragraph Names",                                //       21

                          "-",                                                                                         //       22

                          "18   Break link from story",                                                //       23

                          "19   Joint link to story",                                                       //       24

                          "20   Extract pages",                                                            //       25

                          "21   Joint text fame together",                                           //       26

                          "22   Resize selected text"],                                                //       27

                                         

                                         

                    mReminderString = "\"Batch import styles from source document\" usually cause indents problem.",

                    lastSelected = Number(app.extractLabel("dialogWizard") ),

                    p = w.add("panel", undefined, "Choose a job to do:"),

                    s = p.add("group"),

                    mDD = p.add("dropdownlist", undefined, stringList),

                    mRem = p.add("statictext", undefined, mReminderString, {multiline: true} ),

                    b = w.add('group {orientation: "column"}');

                   

                       mDD.preferredSize = [320,20];

                       mRem.preferredSize = [320,30]; // set reminder height as 20 * line count (here 2 lines)

                       if ( !lastSelected ) mDD.items[0].selected = true;

                       else mDD.items[lastSelected].selected = true;

                         

                  // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||

                              mDD.active = true;                 //this syntax work in PC, but not work in MAC

                              mDD.addEventListener ("keydown", function (k)

                                  {

                                      k = k.keyName.toLowerCase();

                                              var i = 0;

                                                      while (i < numbers.length-1 && numbers[i].charAt(0).toLowerCase() != k)

                                                                 {++i;}

                                                              if (numbers[i].charAt(0).toLowerCase() == k)

                                                                              mDD.selection = i;

                                                                           }

                                            );

                  // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||

                   

                  // |||||||||||||||||||||||||||||||||||||||||||||||| modify reminder font here |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

                           w.graphics.backgroundColor = w.graphics.newBrush (w.graphics.BrushType.SOLID_COLOR, [1, 0.26, 0.2]);

                       mRem.alignment = "left";

                       mRem.graphics.font = ScriptUI.newFont ("Arial", "Bold", 11);

                       mRem.graphics.foregroundColor = mRem.graphics.newPen (w.graphics.PenType.SOLID_COLOR, [1, 1, 1], 1);

                       p.graphics.font = ScriptUI.newFont ("Arial", "Bold", 10);

                       p.graphics.foregroundColor = mRem.graphics.newPen (w.graphics.PenType.SOLID_COLOR, [1, 1, 1], 1);

                       mDD.graphics.font = ScriptUI.newFont ("Arial", "Bold", 11);

                       mDD.graphics.foregroundColor = mRem.graphics.newPen (w.graphics.PenType.SOLID_COLOR, [1, 0.26, 0.2], 1);

                  // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||

                   

                          var myIcon = ""

                          var ib = b.add ('iconbutton', undefined, myIcon);

                                ib.onClick = function() {

                                       w.close(1);

                                  }

                          w.addEventListener ("keydown", function(k) {if (k.keyName == "Enter") w.close(1);})

                  // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||

                          b.add ('button', undefined, "取り消す", {name: "Cancel"}); 

                  // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||

                   

                  w.show();

                  //======================================================================================== =======================================================

                   

                  Thank you

                  Regard

                   

                  John

                  • 7. Re: How to set a keyboard event, which can response to dropdown list?
                    Johnwhite Level 1

                    Hi Uwe

                     

                    thank you for you reponse to me

                    is that my OSX really out of date,

                     

                    my indesign cs5.0 but I don't know the OSX version

                     

                    thanks

                    Regard

                     

                    John

                    • 8. Re: How to set a keyboard event, which can response to dropdown list?
                      Johnwhite Level 1

                      Hi Peter

                       

                      Yes, as you say the script can reponse to digit, but only in first time, the second time will nothing happen unless you press the ok or escape then try next.

                       

                      thank you

                      Regard

                      John

                      • 9. Re: How to set a keyboard event, which can response to dropdown list?
                        Peter Kahrel Adobe Community Professional & MVP

                        Restart InDesign, then fix your script. The one you listed in your post #5 doesn't work, you'll have to replace 'stringList' with 'numbers'. Furthermore you use the wrong handler. Use the one on p. 83, the one that has 'buffer' in it. I tried in CS5.0 and it works fine. With that handler, if I press '1' the dropdown shows '10   DEL and Replace Color', then when I press '3' the dropdown shows '13  Remove layer and missing link', so it works as expected. Again: restart InDesign and make sure you have the correct handler.

                        • 10. Re: How to set a keyboard event, which can response to dropdown list?
                          Johnwhite Level 1

                          Hi Peter

                           

                          thank you so much

                           

                          I'll try once I in office.

                           

                          once again thank you

                           

                          Regard

                          John

                          • 11. Re: How to set a keyboard event, which can response to dropdown list?
                            Johnwhite Level 1

                            Hi Peter, Hi Uwe

                             

                            My Mac OSX is 10.6.8

                            my Adobe version is 5.0

                             

                            the key board for dropdown list not working in Mac system

                            but works very well in Window system

                             

                            John

                            • 12. Re: How to set a keyboard event, which can response to dropdown list?
                              Laubender Adobe Community Professional & MVP

                              @Peter – I tried your snippet from page 82 in your scriptui-2-4.pdf with InDesign CS5 v7.0.4 (German) on Mac OSX 10.6.8 with my MacBook-Pro (late 2008).

                               

                              Started the script snippet from the Scripts Panel.
                              The dialog with the drop-down is showing.

                              Typing "h".

                              The drop-down selection "hundred" did not show up.

                               

                              I checked, that the event listener is added.

                              But the "keydown" event does not work.

                               

                              Only the "esc" key is showing an reaction:
                              Closing the window w.

                               

                              Selecting the indivdual drop-down items by mouse is no problem at all.

                               

                              I did some tests:

                              I registered an event listener with the event "keydown" on the window w itself. Not on the drop-down list ddown.

                              Now this eventlistener is working as expected. It can react to the keys the user is pressing on the keyboard.

                               

                              Using your function with that listener will work as expected.
                              If the user is pressing "h", the item "hundred" is showing up.

                               

                              Uwe

                              • 13. Re: How to set a keyboard event, which can response to dropdown list?
                                Peter Kahrel Adobe Community Professional & MVP

                                Many thanks for testing and reporting this, Uwe. I've made a not of it.

                                 

                                Peter

                                • 14. Re: How to set a keyboard event, which can response to dropdown list?
                                  Johnwhite Level 1

                                  Hi Peter and Uwe

                                   

                                  thank you for you guys help.

                                   

                                  but How can fix, or make a "keydown" on the window w itself. Not on the drop-down list ddown?

                                   

                                  thanks

                                  Regard

                                   

                                  John

                                  • 15. Re: How to set a keyboard event, which can response to dropdown list?
                                    Johnwhite Level 1

                                    Hi Peter and Uwe

                                     

                                    but what if I really want to a drop-down, and need it response to key press?

                                     

                                    Regard

                                    John

                                    • 16. Re: How to set a keyboard event, which can response to dropdown list?
                                      Laubender Adobe Community Professional & MVP

                                      @John – what is the bigger picture behind your request?

                                      Can you explain?

                                       

                                      Right now your window w consists of one single drop-down list.

                                      And if you register the listener to w, you can directly address the right item in the list.

                                       

                                      Like in this snippet, working from keyboard input from 1 to 9, because I did no buffering:

                                       

                                      /*
                                          Tested with:
                                          Mac OSX 10.6.8
                                          InDesign CS5 v7.0.4
                                      
                                          Adding the listener to ddown directly will not work on CS5 on Mac OSX.
                                          Instead the listener is added to window w.
                                         
                                          Will work for typing numbers 1-9 :
                                          How can we catch the typing of double digit number?
                                          Like: 10, 11 etc. ??
                                      
                                          Do it with a buffered value like described in:
                                          Peter Kahrel's scriptui-2-4.pdf on page 83
                                      
                                      */
                                      
                                      function doSomething(myEvent1){
                                         
                                          for(var n=0;n<myNumbers.length;n++){
                                              if(myEvent1.keyName === String(Number(myNumbers[n].replace(/^0+/,"")))){
                                                  ddown.selection = n;
                                                  break;
                                                  }
                                              };
                                      
                                          };
                                      
                                      //Array of strings:
                                      var myNumbers =
                                          [
                                              "01 One",
                                              "02 Two",
                                              "03 Three",
                                              "-",                //Separator string
                                              "04 Four",
                                              "05 Five",
                                              "06 Six",
                                              "-",                //Separator string
                                              "07 Seven",
                                              "08 Eight",
                                              "09 Nine"
                                          ];
                                      
                                      var w = new Window ("dialog", "Drop-down select");
                                      var ddown = w.add ("dropdownlist", undefined, myNumbers);
                                      ddown.minimumSize.width = 200;
                                      ddown.selection = 0;
                                      ddown.active = true;
                                      w.addEventListener ("keydown", doSomething);
                                      w.show();
                                      

                                       

                                       

                                      Uwe

                                      • 17. Re: How to set a keyboard event, which can response to dropdown list?
                                        Johnwhite Level 1

                                        Hi Uwe

                                         

                                        thank you for your help, thank you very much.

                                         

                                        I just want to make some scripts,

                                        and when I run these scripts in Mac OSX without mouse like in window system

                                         

                                        thanks

                                        Regard

                                         

                                        John

                                        • 18. Re: How to set a keyboard event, which can response to dropdown list?
                                          Laubender Adobe Community Professional & MVP

                                          @John – I don't know, cannot test it, but adding the listener to the window instead of the drop-down list should work as well.

                                           

                                          Uwe

                                          • 19. Re: How to set a keyboard event, which can response to dropdown list?
                                            Johnwhite Level 1

                                            Hi Uwe

                                             

                                            Now the dropdown list directly response to digit, but not to arrow key.

                                            Is that any way to fix?

                                             

                                            Regard John

                                            • 20. Re: How to set a keyboard event, which can response to dropdown list?
                                              Laubender Adobe Community Professional & MVP

                                              Hi, John!


                                              Take my code example from my answer #16.


                                              I just tested this with InDesign CC 2014.2 on OSX 10.7.5

                                              The arrow keys are working as expected. I did not expect that. But they are working as they should.

                                              German Keyboard on a MacBook-Pro.

                                               

                                              Key arrow down will advance down in the list, key arrow up will advance up in the list of items.

                                               

                                              I traced the corresponding keyNames, and they were returned as Strings:


                                              "Up"
                                              "Down"

                                               

                                              However did not test on my InDesign CS5 v7.0.4 on Mac OSX 10.6.8.

                                               

                                              Uwe

                                              • 21. Re: How to set a keyboard event, which can response to dropdown list?
                                                Johnwhite Level 1

                                                Hi Uwe

                                                 

                                                the problem is

                                                 

                                                .active = true

                                                 

                                                dropdown list active unfunction

                                                 

                                                if the UI change into multi line list, all the arrow key and the digit, or the alphabet key as function as usual like in window.

                                                 

                                                I don't know why.

                                                 

                                                thank you for your help

                                                Regard

                                                 

                                                John

                                                • 22. Re: How to set a keyboard event, which can response to dropdown list?
                                                  Laubender Adobe Community Professional & MVP

                                                  Now I had the chance to test with InDesign CS.5 v7.5.3. I guess the results will be the same as in CS5.

                                                  The Up and Down arrow keys are not working, but I could trace the typed in key commands with event.keyName.

                                                   

                                                  Conclusion: You have to write your own handler, if your keyName === "Up" or "Down", "Left" or "Right", that reacts to those names.

                                                  Reading out the current selection in your drop-down list and assigning the next or the previous one according what keyName is detected by the event.

                                                   

                                                  Uwe

                                                  • 23. Re: How to set a keyboard event, which can response to dropdown list?
                                                    Johnwhite Level 1

                                                    Hi Uwe

                                                     

                                                    I have no Mac near by

                                                     

                                                    could you please help me test this script?

                                                     

                                                    \\++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++

                                                    function doSomething(myEvent1){  
                                                         
                                                        for(var n=0;n<myNumbers.length;n++){  
                                                            if(myEvent1.keyName === String(Number(myNumbers[n].replace(/^0+/,"")))){  
                                                                ddown.selection = n;  
                                                                break;  
                                                                }  
                                                            };  
                                                     
                                                        };  
                                                     
                                                    //Array of strings:  
                                                    var myNumbers =  
                                                        [  
                                                            "01 One",  
                                                            "02 Two",  
                                                            "03 Three",  
                                                            "-",                //Separator string  
                                                            "04 Four",  
                                                            "05 Five",  
                                                            "06 Six",  
                                                            "-",                //Separator string  
                                                            "07 Seven",  
                                                            "08 Eight",  
                                                            "09 Nine" 
                                                        ];  
                                                     
                                                    var w = new Window ("dialog", "Drop-down select");  
                                                    var ddown = w.add ("dropdownlist", undefined, myNumbers);  
                                                    ddown.minimumSize.width = 200;  
                                                    ddown.selection = 0;  
                                                    ddown.active = true;  
                                                    w.addEventListener ("keydown", doSomething);  
                                                    //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||||||
                                                            w.addEventListener ("keydown", function(u) {if (u.keyName == "Up") w.close();})  // I don't know how to tell script selection - 1
                                                            w.addEventListener ("keydown", function(d) {if (d.keyName == "Down") w.close();})  // I don't know how to tell script selection + 1
                                                    //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||||||

                                                    w.show(); 

                                                    \\++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++

                                                    • 24. Re: How to set a keyboard event, which can response to dropdown list?
                                                      Johnwhite Level 1

                                                      Hi Uwe, Peter

                                                       

                                                      Final Jarek help me change the script into this

                                                      it works very well into Mac

                                                       

                                                      thank you guys

                                                      so appreciate for being help

                                                       

                                                      John

                                                       

                                                      ========================================================================================== ==============================

                                                       

                                                                  function doSomething(myEvent1){  

                                                                     var cSelected = ddown.selection.index;

                                                                     if (myEvent1.keyName === "Up") {

                                                                          if (cSelected == ddown.items.length - 1) {

                                                                              ddown.selection = ddown.items[0]; return;

                                                                              }

                                                                           if (ddown.items[cSelected + 1].type == "item") {

                                                                              ddown.selection = ddown.items[cSelected + 1]; return;

                                                                              }

                                                                          else ddown.selection = ddown.items[cSelected + 2];

                                                                          return;

                                                                          }

                                                                       if (myEvent1.keyName === "Down") {

                                                                          if (cSelected == 0) {

                                                                              ddown.selection = ddown.items.length - 1; return;

                                                                              }

                                                                           if (ddown.items[cSelected - 1].type == "item") {

                                                                              ddown.selection = ddown.items[cSelected - 1]; return;

                                                                              }

                                                                          else ddown.selection = ddown.items[cSelected - 2];

                                                                          return;

                                                                          }

                                                                      for(var n=0;n<myNumbers.length;n++){  

                                                                          if(myEvent1.keyName === String(Number(myNumbers[n].replace(/^0+/,"")))){  

                                                                              ddown.selection = n;  

                                                                              break;  

                                                                              }  

                                                                          };  

                                                                      };  

                                                                   

                                                                  //Array of strings:  

                                                                  var myNumbers =  

                                                                      [  

                                                                          "01 One",  

                                                                          "02 Two",  

                                                                          "03 Three",  

                                                                          "-",                //Separator string  

                                                                          "04 Four",  

                                                                          "05 Five",  

                                                                          "06 Six",  

                                                                          "-",                //Separator string  

                                                                          "07 Seven",  

                                                                          "08 Eight",  

                                                                          "09 Nine" 

                                                                      ];  

                                                                   

                                                                  var w = new Window ("dialog", "Drop-down select");  

                                                                  var ddown = w.add ("dropdownlist", undefined, myNumbers);  

                                                                  ddown.minimumSize.width = 200;  

                                                                  ddown.selection = 0;  

                                                                  ddown.active = true;  

                                                                  w.addEventListener ("keydown", doSomething);  

                                                                  w.show();

                                                      • 25. Re: How to set a keyboard event, which can response to dropdown list?
                                                        Laubender Adobe Community Professional & MVP

                                                        @John – thank you for sharing!
                                                        And of course my thanks go to Jarek as well.

                                                         

                                                        I was destracted from that topic, because of testing, documenting and reporting a severe bug in the latest InDesign CC 2014.2 v10.2.0.69 with groups. :-(

                                                         

                                                        Uwe

                                                        • 26. Re: How to set a keyboard event, which can response to dropdown list?
                                                          Johnwhite Level 1

                                                          anyway thank you all guys

                                                          appreciate

                                                           

                                                          John

                                                          • 27. Re: How to set a keyboard event, which can response to dropdown list?
                                                            Laubender Adobe Community Professional & MVP

                                                            @Peter – in testing further keyboard events by using a listener for keyup or keydown in other circumstances, I have to note, that not all keys pressed are caught exactly good. Sounds odd, but on my German keyboard the more problematic ones are:

                                                             

                                                            ß,ü,ö,ä

                                                             

                                                            with their respected counter parts:


                                                            ?ÜÖÄ

                                                             

                                                            when the shift key is pressed as well.

                                                             

                                                            To monitor what's going on, I added an event listener to a palette type of window with a edittext field and all the properties and values of the event, that I will listen to, will be written in a text frame of an InDesign document for logging immediately when the event is caught by the listener.

                                                             

                                                            Here one sample result for the logged event of type keyup when I am typing the letter ß LATIN SMALL LETTER SHARP S, Unicode 00DF, on my German keyboard.

                                                            Language of the OSX is set to German, InDesign CS5.5 is German as well.

                                                             

                                                            For now showing the whole table of properties and values with some sample outtakes at the start:

                                                             

                                                            myTextEditField.text:    ß

                                                            myEvent1.keyName:    undefined

                                                             

                                                            [object KeyboardEvent]

                                                            Properties and Values:

                                                             

                                                            0    0    keyName    undefined

                                                            0    1    keyIdentifier    undefined

                                                            0    2    keyLocation    0

                                                            0    3    ctrlKey    false

                                                            0    4    altKey    false

                                                            0    5    shiftKey    false

                                                            0    6    metaKey    false

                                                            0    7    DOM_KEY_LOCATION_STANDARD    0

                                                            0    8    DOM_KEY_LOCATION_LEFT    1

                                                            0    9    DOM_KEY_LOCATION_RIGHT    2

                                                            0    10    DOM_KEY_LOCATION_NUMPAD    3

                                                            0    11    view    [object EditText]

                                                            0    12    detail    1

                                                            0    13    captures    true

                                                            0    14    bubbles    true

                                                            0    15    cancelable    true

                                                            0    16    currentTarget    [object Window]

                                                            0    17    eventPhase    bubble

                                                            0    18    target    [object EditText]

                                                            0    19    timeStamp    Sun Mar 01 2015 13:34:55 GMT+0100

                                                            0    20    type    keyup

                                                            0    21    NOT_DISPATCHING    0

                                                            0    22    CAPTURING_PHASE    1

                                                            0    23    AT_TARGET    2

                                                            0    24    BUBBLING_PHASE    3

                                                             

                                                            Same result in CS6 v8.1.0 on OSX 10.7.5

                                                             

                                                            The same script tested with InDesign CC v9.3.0 and CC 2014.2 on the same machine is showing quite different results:

                                                             

                                                            myTextEditField.text:    ß

                                                            myEvent1.keyName:    undefined

                                                             

                                                            0    0    keyName    undefined

                                                            0    1    keyIdentifier    U+00DF


                                                            Here indeed, we have a chance to catch a "ß" by the keyIdentifier value of the events keyup or keydown.

                                                            Same goes for ä, ü, ä – keyName is undefined, keyIdentifier is defined and the right Unicode value.

                                                            Not so with CS5.5 and CS6 v8.1.0.

                                                             

                                                            But unfortunately there are other issues with listening to keyup or keydown in CC and CC 2014.2 opposed to what I see in CS5.5 and CS6:

                                                             

                                                            1. The event will fire three times when one single key is inserted in the edittext field (opposed to CS5.5 and CS6)

                                                            (The event is not registered to the edittext field, but to the window holding the field)

                                                            2. If the enter key is pressed the edittext field and the whole UI window will lose its focus (not so in CS5.5 and CS6)

                                                            3. If shift + enter is pressed the window will not lose its focus.

                                                             

                                                            There are other problems with edittext fields, but I want to concentrate here on eventlisteners for keyup or keydown to monitor keyboard input.

                                                             

                                                            Uwe

                                                            • 28. Re: How to set a keyboard event, which can response to dropdown list?
                                                              Laubender Adobe Community Professional & MVP

                                                              After testing on, I'm a little confused how, how often and on what ocassion these events keyup or keydown are fired.

                                                              If more instances of InDesign are open using the same script.

                                                               

                                                              In my first tests, out of convenience, I had all versions of InDesign I installed open at the same time. Also tested nearly at the same time. Tested with duplicated script files (same code, same #targetengine statement) in all the respective subfolders of each of my InDesign installs double-clicking the file names in the Scripts Panel.

                                                               

                                                              Now I have one single InDesign app open (CC 2014.2) and the listener is reacting differently than before. I still have to sort out what exactly is going on.

                                                              Also made some effort to minimize work when changing some details of the logging and used Macintosh Alias files from the original jsx files, that are itself duplicated to my four Scripts Panel folders of the installs of InDesign CS5.5, CS6, CC and CC 2014.2.

                                                               

                                                              Could it be, that several InDesign apps open at the same time can come in conflict which each other, maybe sharing the same parts of memory, when it comes to eventlistening of keyboard events?

                                                               

                                                              Uwe

                                                              • 29. Re: How to set a keyboard event, which can response to dropdown list?
                                                                Johnwhite Level 1

                                                                Hi Uwe

                                                                 

                                                                Jarek make a little mistake

                                                                now you change DOWN to UP

                                                                and change UP to DOWN

                                                                will work perfectly

                                                                 

                                                                Have fun

                                                                John

                                                                • 30. Re: How to set a keyboard event, which can response to dropdown list?
                                                                  Peter Kahrel Adobe Community Professional & MVP

                                                                  Uwe,

                                                                   

                                                                  It could be that typing certain characters outside the standard ASCII trange in fact sends more than one code. That used to be the case on PCs and is probably still the case, and that's probably also the case on Macs. I remember a dicussion a while ago on HilfDirSelbst about file names with accented characters like ä, and it turned out that on Macs those file names used two characters for those accented characters.

                                                                   

                                                                  Why things work different depending on which apps are open, I've no idea.

                                                                   

                                                                  Peter

                                                                  • 31. Re: How to set a keyboard event, which can response to dropdown list?
                                                                    Laubender Adobe Community Professional & MVP

                                                                    Peter,

                                                                     

                                                                    it's not just the umlauts or "ß" where the event happened three times. Every other character keyed in did that as well. I think, it was the fact, that three different apps of InDesign were opened at the same time and I did not shield my listener good enough from the other apps where the same script was running or has been run and closing the UI window was not removing the listener (I am aware of that point and will change my code).

                                                                     

                                                                    Uwe

                                                                    • 32. Re: How to set a keyboard event, which can response to dropdown list?
                                                                      Laubender Adobe Community Professional & MVP

                                                                      @John – I'm recurring here not to the concrete script Jarek has presented. Just to the general problems listening to keyboard events like keyup or keydown.


                                                                      But thank you for pointing this out.

                                                                       

                                                                      I wonder, if it is necessary using different #targetengine specifiers, even different event variables or different function names for listening to keyboard events when different versions of InDesign are working at the same time on one machine.

                                                                       

                                                                      Also what will happen, if different Adobe apps like PhotoShop and Illustrator are running as well where the #targetengine statement is not part of the DOM.

                                                                      Just a few days back we had one case with a startup script, that is causing an error in Illustrator even if InDesign was addressed as target app. It happend, that just the wrong folder was used for saving the script.

                                                                       

                                                                      Uwe

                                                                      • 33. Re: How to set a keyboard event, which can response to dropdown list?
                                                                        Laubender Adobe Community Professional & MVP

                                                                        Peter,

                                                                         

                                                                        in case the property keyName of the event will return undefined we have the chance to switch to the value of keyIdentifier. At least in CC v9.3.0 and CC 2014.2 this is doable. For CS5.5 and CS6 there is no way to identify, if the user keyed in ß ü ö ä . We could watch for the change in an edittext field and check the value of property text there, but without that, I see no way.

                                                                         

                                                                        Uwe

                                                                        • 34. Re: How to set a keyboard event, which can response to dropdown list?
                                                                          Laubender Adobe Community Professional & MVP

                                                                          Just some other observations when looking at properties for the events keydown and keyup:

                                                                           

                                                                          The value of keyLocation is obviously referring to the four possible DOM_KEY_LOCATION enumerators:

                                                                           

                                                                          DOM_KEY_LOCATION_STANDARD    0

                                                                          DOM_KEY_LOCATION_LEFT    1

                                                                          DOM_KEY_LOCATION_RIGHT    2

                                                                          DOM_KEY_LOCATION_NUMPAD    3

                                                                           

                                                                          Assumption: We can see, if e.g. a number is keyed in from the standard keyboard or the numpad part of a keyboard.

                                                                          LOCATION_LEFT and LOCATION_RIGHT could refer to additional keyboards?! And their position relative to the standard keyboard?!

                                                                          (I have to test this out with a second keyboard with a numpad on my MacBook Pro)

                                                                           

                                                                          After a bit of research I did after writing the lines below, I think this could be well modelled around the following:

                                                                          KeyboardEvent (Apache Batik Javadoc)

                                                                           

                                                                          The value of detail could be (I'm not sure about that) referring to the last four property values of my list:

                                                                           

                                                                          NOT_DISPATCHING    0

                                                                          CAPTURING_PHASE    1

                                                                          AT_TARGET    2

                                                                          BUBBLING_PHASE   3

                                                                           

                                                                          For detail I found the following:

                                                                           

                                                                          As UI Event

                                                                          detail    Number    This value sets the detail property; it can e.g. be a mouse click count.

                                                                          As Property

                                                                          detail    Any    readonly    Passed in to initEvent(); it can e.g. be a mouse click count.

                                                                           

                                                                          Not very enlightening this explanation (at least not to me)…

                                                                           

                                                                          I searched a bit in the available DOM documentation, but all these enumerators* mentioned above are not listed there, I think…

                                                                          But there are some hints at: core W3C events. I wonder, if this hint will lead to something like this:

                                                                          Document Object Model Events

                                                                           

                                                                          * And the enumerators are no enumerators at all, but CONSTANTS (defined as properties ?!).

                                                                          Hm…

                                                                           

                                                                          Uwe

                                                                          • 35. Re: How to set a keyboard event, which can response to dropdown list?
                                                                            Laubender Adobe Community Professional & MVP

                                                                            Ok, I will abandon my hypothesis about event firing when more than one app of the same kind is open.

                                                                            Now, that I made sure, that:

                                                                             

                                                                            1. MacBook Pro is restarted

                                                                            2. Only CC 2014.2 is open, nothing else, even Friefox closed etc.

                                                                            3. I still have the case, that the same code is firing the event three times in InDesign CC 2014.2 or CC.

                                                                            4. One time in CS5.5 or CS6.

                                                                             

                                                                            event is keydown

                                                                            object the listener is attached to is a SUI window of type panel

                                                                             

                                                                            I will sleep it over…

                                                                             

                                                                            Uwe