5 Replies Latest reply on Feb 28, 2013 4:25 AM by J.Kahl

    How can I catch a keyboard input and return another character to Framemaker?

    J.Kahl Level 1

      Hi,

       

      I want to catch an keyboard input and return another character to Framemaker, like e.g. changing a "y" I type into my computer into a "z" and vice versa or changing the arrow key "right" into "Tab".

       

      For me, the biggest issue in this is to find a solution to catch the keyboard input by ExtendScript for further processing. I tried the Notify-function, but it doesn't seem to work like described in the Scripting Guide and I have no idea how to make it work. I hope that someone here knows a solution for at least the keyboard input issue.

       

      Thank you in advance.

        • 1. Re: How can I catch a keyboard input and return another character to Framemaker?
          4everJang Level 3

          Are you sure about this? Processing every character while it is pressed on the keyboard using a script might seriously kill the performance of your FrameMaker.

           

          Just trying to bring in some kind of reality check...

           

          Jang

          • 2. Re: How can I catch a keyboard input and return another character to Framemaker?
            J.Kahl Level 1

            Yes, I am sure about this. But what I will do before further handling is check  if I need the pressed key and abort the script if it is not one of those I need for the issue at hand.

            • 3. Re: How can I catch a keyboard input and return another character to Framemaker?
              frameexpert Level 4

              I think there is an example of this in the FDK documentation. You will have to modify it to work with ExtendScript, but if it works in the FDK, it should work with ExtendScript.

              • 4. Re: How can I catch a keyboard input and return another character to Framemaker?
                J.Kahl Level 1

                Okay, what I did after a day of research in the FDK (and some other) documentation(s), is this piece of code:

                 

                Notification(Constants.FA_Note_PreFunction,Constants.FA_Note_PostFunction, true);

                 

                function Notify(note, object, sparam, iparam) {

                switch (note) {

                    case Constants.FA_Note_PostFunction:

                    break;

                    case Constants.FA_Note_PreFunction:

                        if (sparam=="z") {

                            var tl = new TextLoc();

                            tl=app.ActiveDoc.TextSelection.beg;

                            app.ActiveDoc.AddText (tl, "y");

                            ReturnValue(Constants.FR_CancelOperation);      

                        }

                    break;

                    }

                }

                It does not solve my problem with changing the "z" to a "y" entirely as the cursor stays in front of the y, where as I need it after the y for regular typing, but I think I can solve that problem somehow.

                 

                But I still have problems solving my second issue with catching the arrow keys. I SHOULD get their f-codes by the iparam (or at least the FDK documentation says something like that), but all I get is invalid objects. As the sparam for these keys is null it seems that I am stuck here. Does anyone have an idea how to catch keys that are no regular String characters?

                • 5. Re: How can I catch a keyboard input and return another character to Framemaker?
                  J.Kahl Level 1

                  A working script for the catch and replace issue:

                  Notification(Constants.FA_Note_PreFunction);

                   

                  function Notify(note, object, sparam, iparam) {

                  switch (note) {

                      case Constants.FA_Note_PreFunction:

                          if (sparam=="z") {

                              var tl=app.ActiveDoc.AddText(app.ActiveDoc.TextSelection.beg,"y");

                              var tr= new TextRange(tl, tl);

                              app.ActiveDoc.ScrollToText(tr);

                              ReturnValue(Constants.FR_CancelOperation);

                          }

                      break;

                      }

                  }

                  It is not perfect, but it works just fine (at least when you are not typing too fast, i.e. on a normal user typing rate).

                  But there is still the issue with the iparam that always returns an invalid object (alert(iparam) says "[object InvalidObject]").

                  And how do I execute an f-code like "pressing" the tab-key, when the user presses an arrow key?