3 Replies Latest reply on Jun 28, 2011 12:06 AM by Andreas Jansson

    Run a keyboard shortcut?

    curtis368

      Is it possible to use java script or VB to simply call a keyboard command?

       

      I need to do ctrl+shift+u, folllowed by ctrl+shift+m, if that helps at all, and thats all i want the script to do. No menus, no gui's ect. Thank you so much to anyone that can help. I feel like I'm gona have to completely learn java script or VB just to figure out how to do these little simple commands, and I'm hoping thats not the case.

        • 1. Re: Run a keyboard shortcut?
          [Jongware] Most Valuable Participant

          I'm sorry to say, but it *is* necessary to learn the backgrounds. A script doesn't "do" a sequence of key commands; instead, it does the commands themselves. You can compare it to this: "Ctrl+Shift+U" -- what would that do for a user who changed all of the key assignments?

           

          Presumably, you want to enable underline (although technically the keystroke "Ctrl+Shf+U" is not an enable, it's a toggle!) and then insert an em space. That only works in text mode, and the wise scripter first tests if InDesign *is* in text mode before attempting to perform these actions. Then it's only a matter of invoking the right magic commands:

           

          if (app.documents.length > 0 && app.selection.length == 1 && app.selection[0].hasOwnProperty("baseline"))
          {
               app.selection[0].insertionPoints[-1].underline = true;
               app.selection[0].insertionPoints[-1].contents = SpecialCharacters.EM_SPACE;
          }
           
          

           

           

          As you can see I start with checking if there are any documents open (more than none is good), then if there is a single selection (the 'text cursor' only allows a single selection; other than the black arrow cursor, for example), and finally if the selection has a property "baseline", which is a trick I learnt from this very forum to check if the cursor is anywhere inside a text frame.

          Only then, the attributes at the "cursor" position are changed to enable underline, and a special character is inserted at that position.

           

          This is a very modest script, by the way. Calling it up is hardly any less effort than the sequence press Ctr+Shift+U, release U, press M, release all keys.

          • 2. Re: Run a keyboard shortcut?
            curtis368 Level 1

            Oh ok, well that stinks, but thank you very much for the help!

            • 3. Re: Run a keyboard shortcut?
              Andreas Jansson Level 2

              Why does it stink, in your opinion? Did jongware's script do the things you asked for?

               

              If you really want to (for some unknown reason), I guess you could do exactly what you ask for, using SENDKEYS from VB, or similar command in other languages (not in the built-in parser though). This would however stink more, in my opinion.

               

              Best regards,

              Andreas