• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Community Beginner ,
Feb 26, 2013 Feb 26, 2013

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Feb 26, 2013 Feb 26, 2013

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 26, 2013 Feb 26, 2013

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 26, 2013 Feb 26, 2013

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 27, 2013 Feb 27, 2013

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 28, 2013 Feb 28, 2013

Copy link to clipboard

Copied

LATEST

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines