PerfectScript Journal
 

November 1997: Using WordPerfect Dialogs in Your Macros  

WordPerfect includes a set of macro commands that display WordPerfect's own dialog boxes during your macro. When you play a macro with a dialog box command in it, the dialog box will display on the screen until the user provides input and dismisses the dialog box. Then the next command in the macro will be executed.

But in some cases you may want the macro to interact with the dialog box before the user does. For instance, you may want to make sure a certain check box is checked.

To successfully use WordPerfect dialogs in your macro, there are a few commands you should be familiar with. These are InhibitInput, InvokeDialog, and CoachAnimate. Another command, SendKeys, can also be used, but I won't cover that command here.

The InhibitInput Command

Normally, user input during a macro (except during a PAUSE command or when a dialog box is waiting for user input) is ignored while a macro is playing. The InhibitInput command can be used to allow interaction with the dialog while the macro is playing. When you use this command, the macro itself can simulate keystrokes, just as though the user had performed them, using the CoachAnimate or SendKeys command.

The InhibitInput command has one parameter called State, with two possible states: Off! and On!. The default is InhibitInput(On!). When InhibitInput is on, the macro is suspended while the dialog is displayed, and doesn't continue until the dialog is dismissed by the user. If InhibitInput is off, the macro can send keystrokes via the CoachAnimate command to a dialog box. (Any clicks or keystrokes the user performs will also be allowed.)

In order for InhibitInput to be effective, you should display the dialog with the InvokeDialog command.

The InvokeDialog Command

The InvokeDialog command is a product command used to open a WordPerfect dialog on the screen. Normally, when you use a dialog command without InvokeDialog, such as BulletDlg, the macro displays the dialog, then pauses to allow the user to interact with that dialog. When the user dismisses the dialog, the macro will continue. Thus, the macro cannot actively interact with the dialog.

If you need the macro to interact with a dialog, however, you must open the dialog in a way that will not cause the paused condition to occur. This is where the InvokeDialog command comes in. When you open a dialog with the InvokeDialog command, the macro does not pause, and additional macro commands can interact with that dialog.

The InvokeDialog command has one parameter. The normal dialog command to open the dialog you need is inserted in this parameter. For example,

InvokeDialog(BulletDlg)           

The CoachAnimate Command

The CoachAnimate command was created to allow the WordPerfect Coaches to automatically animate the mouse pointer to various locations on the screen, or to automatically simulate keystrokes. You can also use it to interact with dialogs, toolbars, or other WordPerfect screen objects in your macros.

Since sending keystrokes or mouse movements and clicks with CoachAnimate simulates a person doing the same thing, you should include an InhibitInput(Off!) command prior to a CoachAnimate command to allow the commands to go through.

You can use CoachAnimate to simulate keystrokes or mouse movements. To specify which type you wish to use, place one of the following in the Type parameter.

Keyboard!: With this type, you can send keystrokes to the dialog. The keystrokes are specified in the Specification parameter.

Mouse!: With this type, you can animate the mouse pointer to a specific place on the dialog. You'll need specify the region name of the location on the dialog that you want to interact with in the Specification parameter.

In the Specification parameter, you will specify what keys or movements you want to take place. If you choose the Keyboard! Type, the Specifications parameter will include keystrokes.

If you choose the Mouse! Type, you'll specify an action and a named region that the action should work on.

Here's an example of using these commands in a macro. This example opens the Margins dialog, moves among the various entry windows, then sets the left margin to 1.5 inches.


InhibitInput(off!)
InvokeDialog(FormatMarginsDlg)
CoachAnimate(Keyboard!; "{Alt+R}")
Wait(5)
CoachAnimate(Keyboard!; "{Alt+T}")
Wait(5)
CoachAnimate(Keyboard!; "{Alt+B}")
Wait(5)
CoachAnimate(Keyboard!; "{Alt+L}")
Wait(5)
CoachAnimate(Keyboard!; "1.5i")
WAIT(5)
CoachAnimate(Mouse!; "click on WordPerfect.Margins.OKBttn")
           

For more information on named regions, or the commands covered in this feature, see the WordPerfect Macro Online Help, or my book.

For information on ordering my book see my web page.

 

Copyright Notice: The information included in the PerfectScript Journal is protected by US Copyright. The author grants you the right to use the routines in your own macros as needed. You may not sell, distribute, or publish them in any form.
If you choose to use the information here, you do so entirely at your own risk. No representations are made regarding the fitness of this information for your   particular purpose, or for your ability or inability to use the information. You   are advised to make backups of all relevant files before implementing any suggestion  or technique.
© Copyright 1997 by J. Jeppson.