9 Replies Latest reply on Jan 17, 2013 10:20 AM by Pickory

    Capture Keyboard Event [CS6]

    Mac_06 Level 2

      Hi

       

      I need to capture key event in InDesign. I tried it using 'keydown' event but it gives error: "keydown" is not a recognized event type

       

       

      app.addEventListener ("keyDown", function(k){
               if(k.escKey)
                 {
                   if(app.activeDocument && app.activeDocument.placeGuns.loaded)
                       app.activeDocument.placeGuns.abortPlaceGun();
                 }
          })
      
      

       

      Can some one let me know, what I'm doing wrong or how to capture that event.

       

      Thanks

      Mac

        • 1. Re: Capture Keyboard Event [CS6]
          Peter Kahrel Adobe Community Professional & MVP

          You don't tell us in which environment you're using that event listener. I think it's ScriptUI-only. If you are using it in the context of ScriptUI, its name should be all lower case: "keydown".

           

          Peter

          • 2. Re: Capture Keyboard Event [CS6]
            Mac_06 Level 2

            Hi Peter,

             

            This context works fine in Script UI (with all lowercase) but I'm looking for adding keyboard event listener in InDesign application context.

            My requirement is on press of escape key if place gun is loaded it should be unloaded.

             

            -Thanks

            -Mac

            • 3. Re: Capture Keyboard Event [CS6]
              Marc Autret Level 4

              Hi Mac,

               

              The DOM does not seem to expose key or mouse events at the Application level.

               

              Full list of supported DOM events:

              alert( Event.reflect.properties.join('\r') );

               

              @+

              Marc

              1 person found this helpful
              • 4. Re: Capture Keyboard Event [CS6]
                Mac_06 Level 2

                Hi Marc,

                 

                Does it support keyboard event at document level ? How Can i see what are the event supported by a particular object ?

                 

                Thanks

                Mac

                • 5. Re: Capture Keyboard Event [CS6]
                  Harbs. Level 6

                  Nope. I don't think there's keyboard events anywhere other than in ScriptUI or CS Extensions.

                  • 6. Re: Capture Keyboard Event [CS6]
                    [Jongware] Most Valuable Participant

                    Does it support keyboard event at document level ? How Can i see what are the event supported by a particular object ?

                     

                    It's somewhere in the ESTK Help, and (from memory) also mentioned in Adobe's Javascript Guide.

                     

                    See also http://jongware.mit.edu/idcs6js/pc_Application.html#AFTER_ACTIVATE and the items following it.

                    • 7. Re: Capture Keyboard Event [CS6]
                      Marc Autret Level 4

                      Mac_06 wrote:

                       

                      Does it support keyboard event at document level ? How Can i see what are the event supported by a particular object ?

                       

                       

                      I don't think so.

                       

                      By saying "at the Application level" I meant that keyboard/mouse events are not implemented at all in the scope of the applicative scripting model (by contrast with ScriptUI).

                       

                      Note: It's a misconception to think events as owned or triggered by some particular DOM objects. In fact, objects can listen to events (through the addEventListener methods), and usually any object can listen to any event depending on the capturing method and the event phase. During its propagation, an event (instance) provides properties such as target or currentTarget that give details on the context, but there is no actual connection between the event and some object specifier. The event is triggered by the subsystem.

                       

                      In CS5 and later we have six fields of events, represented by the following 'classes': Event (base class), DocumentEvent, MutationEvent, ImportExportEvent, PrintEvent, IdleEvent. These are just prototyped APIs for all the event types that InDesign accept to make available within the DOM:

                       

                      AFTER_ACTIVATE  [Event]
                      AFTER_ATTRIBUTE_CHANGED  [MutationEvent]
                      AFTER_CLOSE  [DocumentEvent]
                      AFTER_CLOSE  [Event]
                      AFTER_CONTEXT_CHANGED  [Event]
                      AFTER_DELETE  [Event]
                      AFTER_EMBED  [Event]
                      AFTER_EXPORT  [ImportExportEvent]
                      AFTER_IMPORT  [ImportExportEvent]
                      AFTER_INVOKE  [Event]
                      AFTER_LINKS_CHANGED  [Event]
                      AFTER_MOVE  [Event]
                      AFTER_NEW  [DocumentEvent]
                      AFTER_NEW  [Event]
                      AFTER_OPEN  [DocumentEvent]
                      AFTER_OPEN  [Event]
                      AFTER_PLACE  [Event]
                      AFTER_PRINT  [PrintEvent]
                      AFTER_QUIT  [Event]
                      AFTER_REVERT  [DocumentEvent]
                      AFTER_SAVE  [DocumentEvent]
                      AFTER_SAVE_AS  [DocumentEvent]
                      AFTER_SAVE_A_COPY  [DocumentEvent]
                      AFTER_SELECTION_ATTRIBUTE_CHANGED  [Event]
                      AFTER_SELECTION_CHANGED  [Event]
                      AFTER_UNEMBED  [Event]
                      AFTER_UPDATE  [Event]
                      
                      BEFORE_CLOSE  [DocumentEvent]
                      BEFORE_CLOSE  [Event]
                      BEFORE_DEACTIVATE  [Event]
                      BEFORE_DELETE  [Event]
                      BEFORE_DISPLAY  [Event]
                      BEFORE_EMBED  [Event]
                      BEFORE_EXPORT  [ImportExportEvent]
                      BEFORE_IMPORT  [ImportExportEvent]
                      BEFORE_INVOKE  [Event]
                      BEFORE_MOVE  [Event]
                      BEFORE_NEW  [DocumentEvent]
                      BEFORE_OPEN  [DocumentEvent]
                      BEFORE_PLACE  [Event]
                      BEFORE_PRINT  [PrintEvent]
                      BEFORE_QUIT  [Event]
                      BEFORE_REVERT  [DocumentEvent]
                      BEFORE_SAVE  [DocumentEvent]
                      BEFORE_SAVE_AS  [DocumentEvent]
                      BEFORE_SAVE_A_COPY  [DocumentEvent]
                      BEFORE_UNEMBED  [Event]
                      BEFORE_UPDATE  [Event]
                      
                      FAILED_EXPORT  [ImportExportEvent]
                      ON_IDLE  [IdleEvent]
                      ON_INVOKE  [Event]
                      

                       

                      I suppose this list may evolve in the future...

                       

                      @+

                      Marc

                      • 8. Re: Capture Keyboard Event [CS6]
                        Mac_06 Level 2

                        Thanks for all your support and guidence now it's pretty clear that InDesign doesn't support keyboard event except Script UI and CS Extension. I've to look other workaround only.

                         

                        -Mac

                        • 9. Re: Capture Keyboard Event [CS6]
                          Pickory Level 3

                          How do unload the place gun?

                           

                          Just thought, you could set a command key to a script that uloads it.

                           

                          P.