ExtendScript of the Week: Keyboard Simulation in FrameMaker via Fcodes


Fcodes could be called as JIT automation for FrameMaker. I.e. with minimal effort, one could automate FM tasks with it. If you are a starter it could be very effective in automating some of the small tasks – in a breeze!

Fcodes are small programmatic commands/constants that can automatically simulate user input within FrameMaker. It is relatively (very) easier to automate small tasks via Fcodes than using the real API functions. It’s not that I am proposing ‘not’ to use API functions, but it is just an alternative for starters who would like to automate ‘small tasks in small time’. Fcodes are not new, they exist since very early versions of FM. With ExtendScript, they have become a little bit easier to use.

Fcodes are actually hexadecimal codes that specify individual user actions in FM. There are 1000+ Fcodes available with FM that a user may use. The entire list of Fcodes can be found in <FDK installation>\include\fcodes.h (and FDK can be downloaded from http://www.adobe.com/devnet/framemaker.html).

There are 2 ways to use Fcodes:

  1. via Extendscript
  2. or via FDK Client.

We can use the Fcodes in FM Extendscript (.jsx) or the FM API (.dll). The function Fcodes() in Extendscript / F_ApiFcodes() in API respectively can be used to execute fcodes command. The fcodes command works like this: it sends an array of Fcodes to FrameMaker which is executed in FM, one by one (as if the user performed the action manually).

Method File Type Function Used
Extendscript .jsx Fcodes()
FDK API Compiled as .dll F_ApiFcodes()


The example below describes some extremely simple code on how to create ExtendScript-based Fcode clients for simulating user actions in FrameMaker.

Simple steps:

  1. In FM10, File -> Script -> New Script (script editor opens)
  2. copy paste just few lines of code from e.g.1 or 2.
  3. Simply click Execute or F5.

Example 1: Writing Text in the Document via script

Fcodes can be used to simply write in a document or a dialog automatically. The 2-line example below shows how easily one could write in the document via Fcodes in ExtendScript.

FcodeList = new Array(FCodes.CSR_TOP, 'HI!', Fcodes.HIGH_WORD_PREV, FCodes.TXT_BOLD); //Fcodes
Fcodes(FcodeList); // Fcode Execution

Example 2: Add Misspelled words (Squigglied words) to User Dictionary via script

We have a scenario where we have written a document that has been checked for spellings but still has some keywords that show as misspelled. The user would like to learn all those words (add them to user dictionary). By executing an Fcode we may add all those keywords to our user dictionary. Here’s how to do it (this example adds the first misspelled word to the user dictionary):

FcodeList_Pers = new Array(FCodes.KBD_CHECKDOC, FCodes.KBD_ADDUSRDICT); //Fcodes
for (i=1; i<=1; i++) // Loop -> 1 could be made n
 Fcodes(FcodeList_Pers); //Execute Fcode

Example 3: Setting custom value in Paragraph Line Spacing dialog via script

We have a scenario where we need to set the paragraph line spacing to a particular value. We just need to traverse to the paragraph(s) and execute this Fcode. Important: This type of script that involves dialog focus needs to be run from within FM only. (via File -> Script -> Catalog/Run [a saved script])

FcodeList = new Array(FCodes.PGF_LINE_SPACE, FCodes.START_DIALOG, FCodes.KBD_ItemNextLogical, '4','0', FCodes.KBD_RETURN, FCodes.END_DIALOG); // Fcodes
Fcodes(FcodeList); // FCodes Execution

Description of the Fcodes as used in Example 3:

  • FCodes.PGF_LINE_SPACE opens “Paragraph Line Spacing” dialog
  • FCodes.START_DIALOG denotes the dialog is in use
  • FCodes.KBD_ItemNextLogical denotes SINGLE TAB in the dialog (i.e. pressing a TAB key in dialog takes the focus to the text field)
  • '4','0' writes the value 40 instead of 42. (Since the text field 42 is already selected after pressing the tab)
  • FCodes.KBD_RETURN performs the “Set” (also closes the dialog)
  • FCodes.END_DIALOG denotes the dialog is not in use now
  • Fcodes(FcodeList) statement executes the above sequence of Fcodes

With this information and examples, we should be able to write simple snippets for automating our tasks in FM. For reference, the entire list of Fcodes is being attached.

Important Points

  • Do a manual traversal of the workflow before executing Fcodes.
  • Each Fcode need to be preceded by “FCodes.”
  • Any Fcode client during automatic execution needs to gain the focus so it is imperative we stop the mouse & keyboard activity when the Fcode based client runs.
  • The .jsx file containing Fcodes on dialogs should be executed from the “Script Explorer” ONLY
  • When a dialog launches another dialog use END_DIALOG for previous START_DIALOG for the newly launched dialog.
  • There is an existing issue with Fcodes not working properly over the Book (Bug# 3099221)

Do let us know your story with Fcodes for FrameMaker!


Posted on 02-27-2012


  • By Franz J. Gigler - 7:08 PM on September 21, 2017   Reply

    I’ve come up with the following three liner which may be useful for others too:

    function autoResizeColumnsToCellsContents(tbl) {
    tbl.MakeTblSelection (0, tbl.TblNumRows-1, 0, tbl.TblNumCols-1);
    var FcodesList = new Array(FCodes.KBD_TABLE_RESIZECOL, FCodes.START_DIALOG, FCodes.KBD_ItemNextLogical, FCodes.KBD_ItemNextLogical, FCodes.KBD_ItemNextLogical, FCodes.KBD_ItemNextLogical, FCodes.KBD_ItemNextLogical, ‘8’, ‘ ‘, ‘c’, ‘m’, FCodes.KBD_RETURN, FCodes.END_DIALOG ); // Build List of FCodes
    Fcodes(FcodesList); //Execute FCodes
    Unfortunately I couldn’t find another (more robust?) method to use that special feature of the Resize Selected Columns dialog from Extendscript. Does anybody know one?

  • By max_drawdown - 9:31 PM on January 21, 2013   Reply

    “There is an existing issue with Fcodes not working properly over the Book (Bug# 3099221)”

    How about now?

  • By Kevin MacDowell - 5:17 PM on October 24, 2012   Reply

    I am getting an “FCodes is undefined” error when trying to run the example above.

  • By Jason Langkamer-Smith - 6:09 PM on February 29, 2012   Reply

    How would you apply a paragraph format? I found FCodes.KBD_PGFWIN, which bring up the paragraph catalog. But then what? Thanks!

Join the discussion