"Two-key" macros can help organize
related macros or tasks under a common keystroke combination.
Press one shortcut key combination (e.g., Alt+z) to
play the macro, then a second key (e.g., "1") to perform some action. (Here: "Alt+z+1". You could then use "Alt+z+2" etc. for another task.)
Related pages -
"Two-tap macros" - How to press a keyboard key twice in succession to perform a task, play another macro, etc.
Double duty macros - Make
a key do "double duty" by assigning a macro to it, and make the macro
play only if the key is struck multiple times (e.g., 3x, 4x, etc.) |
|
NOTE: The following material
assumes you know how to edit macros and make simple changes (e.g.,
to add your own text). If not, see here
for general instructions. |
Here are some sample "2-key" macros
for WordPerfect. They can be assigned to a keystroke combination.
For help assigning macros to keys, click here.
- When the first macro below
is played it will wait for any alphanumeric key (as well as Backspace,
Delete, and Ctrl+Enter) and then take whatever action is set
up for that key in the CaseOf commands.
- The second macro below uses
the Char() command to display a small dialog and get the second
keystroke. It will then take whatever action is set up for that
key in the CaseOf commands.
- The third macro below, written
by Roy Lewis and posted on WP Universe, uses push buttons on
a menu as the second keystroke.
- The fourth macro below uses
push buttons to apply UPPER case, Initial Caps,
or lower case to the current word or selection of text.
- The fifth macro below uses
push buttons to insert various closing for letters ("Sincerely
yours," etc.).
- See more sample macros in Footnote
1 below.
- Another macro on this site, QWIKSET ("Quickly set relative font sizes and other attributes with a
keystroke") uses a push-button menu, where the push buttons can also be "pushed"
with a keyboard key -- making the macro a "2-key" macro.
You press a key combination (e.g., <Alt+Z>) then press
a second letter or number. With QwikSet, this causes the macro
to dismiss the menu and execute the command.
|
SAMPLE
MACRO #1
[To copy this macro into your
WordPerfect, see here.]
// Macro begins here -
OnCancel(End@)
OnError(End@)
PauseKey(Any!) // Wait for
any key to be pressed
// Depending on which key
is pressed, carry out the // action(s) below
- Switch(?PauseKey)
// Note the following 6
choices. They are intended to // demonstrate
the general command format.
// However, if the macro
is played "as is," the keys would
// simply cause the macro to terminate, so you must insert
// macro commands that perform some action after
// (to the right of) each CaseOf command.
// Note that since there is
a Default command at the end of
// all commands to terminate the macro, any keys that are
// not assigned to a CaseOf statement will cause the macro to
end.
CaseOF ("0"):
CaseOF ("1"):
CaseOF ("2"):
CaseOF ("a"):
CaseOF ("b"):
CaseOF ("c"):
// ... etc.
// The following Default command
executes if the second key
// is something other that a key specified in the CaseOF // commands above
Default: vKey:=?Pausekey
MessageBox(; "No key
assigned"; "The second key you just pressed, < "
+vKey+ " >, has not been assigned to this macro."
+NToC(0F90Ah)+ "Edit this macro and assign the key inside
the macro's Switch command.")
Return
Endswitch
Label(End@)
Return
// Macro ends here
If, for example, the macro had this CaseOf
statement-
CaseOF ("q"): If(?Substructure)
SubstructureExit Endif CloseNoSave() Go(End@)
- and the macro was saved and assigned to
the <Ctrl+k> keys, then pressing <Ctrl+kq> would
cause the current file to be closed without saving it (i.e.,
it would "quit" the file). (Remember WordStar? This
is one of WordStar's commands.) |
|
SAMPLE
MACRO #2
The next macro is slightly less complicated,
and has the virtue of prompting the user with a dialog box. However,
some people are annoyed with such a dialog, and may prefer the
first dialog-less macro above.
Note that the accented
letters used in the CaseOf commands shown in the example below
were entered using the numeric keypad. For example, the è
between the quote marks in the third Type() command was entered
using <Alt+0232> on the numeric keypad. A list of the numerical
values for these special characters can be found in the Windows
character map (Start, Programs, Accessories, System Tools, Character
Map).
[To copy this macro into your
WordPerfect, see here.]
// Macro begins here -
OnCancel(End@)
OnError(End@)
Char(nextc; "Enter a
vowel: ")
vKey:=NToC(nextc)
Switch(NToC(nextc))
CaseOf "a": Type("à")
CaseOf "A": Type("À")
CaseOf "e": Type("è")
CaseOf "E": Type("È")
CaseOf "u": Type("ù")
CaseOf "U": Type("Ù")
Default: MessageBox(;
"No key assigned"; "The second key you just pressed,
< " +vKey+ " >, has not been assigned in this
macro." +NToC(0F90Ah)+ "Edit this macro and assign
the key inside the macro's Switch command.") Return
EndSwitch
Label(End@)
Return
// Macro ends here
TIP
Inserting accented
characters
With Windows Vista/7 the macro command SendKeys()
-- which has the ability to send keystroke combinations to the
program -- is effectively broken. You have to disable
the User Access Control (UAC) in those versions of Windows
to make such text/symbol keystrokes work (script commands such
as {Ctrl} or {Alt} still will not work). Disabling the UAC is
something that is not generally recommended.
Therefore ...
Since the Sample Macro #2 above is designed
to insert various accented letters, the letters were entered
in the macro code's Type() commands with the numeric keypad
using an <Alt+nnn> combination, as explained above. This
technique works in most other word processors or text editors.
However, you might want to know that there
are alternative ways to create accented characters directly
in the document without using a macro with Switch..CaseOf..Endswitch
commands or one with pop-up dialog prompts, as demonstrated above.
Alternatives:
From Charles Rossiter, Corel C_Tech:
1. "Get an International Keyboard, or
apply [in Control Panel, Keyboard] the US International keyboard
definition to a standard US keyboard. This then works in all
applications. [Windows XP users: For instructions, see the Microsoft
Support Article # 306560, "How To Use the United States-International
Keyboard Layout in Windows XP," at http://support.microsoft.com/default.aspx?scid=kb;en-us;306560]
2. In WPWin, create a series of keyboard keystrokes.
For example, I use Alt+e for e-acute, Ctrl+Shift+E for E-grave,
Alt+a for a-umlaut, Alt+Shift+O for O-umlaut, Alt+Shift+C for
C-cedilla, etc. There is no conflict with other Alt-key shortcuts
(eg Alt+a for T_a_ble): Alt+a gives a-umlaut; Alt,a gives T_a_ble
(i.e., press and release the Alt key, then press a)."
NOTE: To use the second method (assign the
accented letter to a key combination), follow the steps outlined
here (see especially the section, "For
keystrokes").
3. Use a utility such as the free program,
AllChars, at http://allchars.zwolnet.com/.
See the Introduction link on the home page for more information.
(Not tested by this author, but recommended by other knowledgeable
WordPerfect users.)
Alternative: A
more broadly useful program (not free, but a trial version is
available) is As-U-Type at http://www.asutype.com/,
which works well with WordPerfect's QuickCorrect, too.
|
|
SAMPLE
MACRO #3
See Roy Lewis's macro on WP Universe at http://www.wpuniverse.com/vb/showthread.php?postid=40594#post40594.
When a button is pushed from the macro's main dialog, this example
macro types a word corresponding to the button's label. You will
need to modify the macro's menu and other commands, but those
familiar with writing WP macros should have little trouble doing
this. |
|
SAMPLE
MACRO #4
The following
material -- plus the separate function described in Footnote
1 -- has been incorporated into a downloadable multiple-choice
macro on this side, Convert
Case. It can be used as a "2-key" macro, too. |
Here is a two-keystroke macro to apply UPPER
case, Initial Caps, or lower case to the current
word or a selection of text.
[Note: Since WordPerfect's built-in conversion
of text to all lower case leaves the first word of every sentence
capitalized, see Footnote 1 below for a different
macro that can convert all selected text to lower case.]
Assign the macro to a key and then, when the
menu appears, press "u", "i", or "l".
(Or press "a" to abort.)
The word(s) will then be toggled to UPPER
case, Initial Caps, or lower case. (See note #1 below.)
If you do not select anything before playing
the macro, it will select the current word if the cursor is on,
or just after, a word.
Notes
1. If you have selected an all-upper case
(or initial capped) word that begins a sentence, it will still
have its first letter capitalized when "lower case"
is chosen. (This also happens when you use the Edit, Convert
Case menu in WordPerfect)
2. Note also that the word(s) will remain
selected after you play the macro to let you further process
the selection. If this is not desired, remove the two slash marks
from the front of the SelectOff
command.
[To copy this macro into your
WordPerfect, see here.]
// Macro begins here
OnCancel(EndItNow@)
// First, if nothing is selected,
select the current word:
If(?BlockActive=False) SelectWord Endif
Display(On!) // (turn on so we can see selection on screen)
// Display a "push button"
menu:
DialogDefine ("CT";50;50;75;75;Percent!;"Case
Toggle")
DialogAddPushButton ("CT";101;2;3;70;14;0;"&UPPER
case")
DialogAddPushButton ("CT";102;2;19;70;14;0;"&Initial Caps")
DialogAddPushButton ("CT";103;2;35;70;14;0;"&lower
case")
DialogAddPushButton ("CT";104;7;55;60;14;0;"&Abort")
DialogShow ("CT";"WordPerfect";;104)
// Store the menu choice and
use it in the Switch command:
vAns:=MacroDialogResult
Switch(vAns)
CaseOF 101: ConvertCaseUppercase
CaseOF 102: ConvertCaseInitialCaps
CaseOF 103: ConvertCaseLowercase
Endswitch
// Exit here:
Label(EndItNow@)
// If you want to de-select the item after it is processed
// remove the leading slash marks from the next command:
//SelectOff
Return
// Macro ends here
Tip
If you use Initial Caps in titles and
headlines, see the style tip here.
|
|
SAMPLE
MACRO #5
Here is a two-keystroke macro to insert a
letter's closing at the current cursor location. Notice that
it adds a horizontal graphics line above the person's name.
You will want to change the names in the DialogAddPushbutton
commands and also in the Switch commands.
Assign the macro to a key and then, when the
menu appears, press the button to insert the name or press "a"
to abort.
[To copy this macro into your
WordPerfect, see here.]
// Macro begins here
OnCancel(EndItNow@)
Display(On!)
// Display a "push button" menu:
DialogDefine ("Choices";50;10;80;75;Percent!;"Closings:")
DialogAddPushButton ("Choices";101;2;3;75;14;0;"&David
Smith")
DialogAddPushButton ("Choices";102;2;19;75;14;0;"&Susan
Doe")
DialogAddPushButton ("Choices";103;2;35;75;14;0;"Sally
&Jones")
DialogAddPushButton ("Choices";104;10;55;60;14;DefaultBttn!|CancelBttn!;"&Abort")
DialogShow ("Choices";"WordPerfect")
// Store the menu choice and use it in the Switch command:
vAns:=MacroDialogResult
If(vAns=2) Quit Endif
// Start the closing:
Type("Sincerely yours,")
HardReturn HardReturn HardReturn HardReturn
// Add a signature line:
GraphicsLineCreate ()
GraphicsLineSpacing (TopSpace: 0.0"; BottomSpace: 0.05")
GraphicsLineLength (Length: 3.0")
GraphicsLineHorizontalPosition (Position: Left!)
GraphicsLineEnd (State: Save!)
HardReturn
// Insert the name:
Switch(vAns)
CaseOF 101: Type("David Smith, Jr.")
CaseOF 102: Type("Susan Doe")
CaseOF 103: Type("Sally Jones")
Endswitch
HardReturn
// Exit here:
Label(EndItNow@)
Return
// Macro ends here
|
|
|
Footnote 1
Some of the following
material (particularly the code in Sample macro #6) has been
incorporated into a downloadable multiple-choice macro on this
side, Convert Case. |
WordPerfect's built-in conversion to all lower
case (e.g., Edit, Convert Case, Lower case -- or the macro equivalent,
ConvertCaseLowercase) still leaves the first word of every
sentence capitalized, so if you have large blocks of text
and you want all of it to be in lower case, either of the following
macros should do the job.
[Always make a backup of your document first.
To copy a macro from an
Internet site (like this one) see here.]
The first macro is a "brute force"
approach that looks at each character in the selection and, if
it is upper case, it converts it to lower case, then it proceeds
to the next character. It stops when it encounters a user-defined
"terminator" character (here, the Greek omega symbol;
all WordPerfect symbols are seen as "characters" by
macros).
The second (and newer) macro is more elegant
since it first converts the selection to lower case using the
built-in command, ConvertCaseLowercase; then it removes remaining
upper case letters with a Search/Replace routine (which uses
a 2-dimension array).
One virtue of these approaches is that they
preserve all existing formatting, since they only change upper
case characters to lower case characters, skipping over any formatting
codes. [A small, three-command macro that can do the same thing
and remove all formatting at the same time was posted
by Roy ("lemoto") Lewis on 02/24/09 in the Corel WPX4
newsgroup: SelectAll vT
= ToLower(?SelectedText) Type(vT).]
The general methods used might be useful in
other macros.
Sample
macro #6
|
Important
- This macro uses the Greek omega symbol
(8,50) where indicated with ? symbols below, as a "terminator" to tell
the macro when to stop. You should insert this symbol using WordPerfect's
Insert, Symbol (choose the Greek set, symbol number 8,50) in
place of the ? symbols shown between the double quote marks in both
the Type() and While() commands below.
- You can use any character symbol that is
not used elsewhere in the document. The omega symbol was an arbitrary
choice for this macro on the assumption it probably would not
exist in most users' documents.
- It might take some time to finish converting
characters in a very large document and/or on some systems. You
should see its progress in the WordPerfect status bar. You can
always stop it by right-clicking the WordPerfect "cassette"
icon in your system tray at the bottom right of your desktop.
[Sample macro #6 below is probably faster in must situations.]
- [To copy this macro into
your WordPerfect, see here.]
// Macro begins here:
// Converts all UPPER case
characters to lower case
// in a large SELECTION of text.
// First, if nothing is selected,
select the current word:
If(?BlockActive=False) SelectWord Endif
// Next, bookmark the selection:
BookmarkCreate("TempMarker")
BookmarkBlock("TempMarker")
PosBlockBottom
SelectOff
// Add a "terminator"
character (from symbol set 8,50):
Type("?") // <= use WP symbol 8,50 here
BookmarkBlock("TempMarker")
PosBlockTop
SelectOff
BookmarkDelete("TempMarker")
// Step through the selection:
While(?RightChar<>"?")
// <= use WP symbol
8,50 here
// If it's a code or anything other than
// an upper-case character, skip it:
If(?RightCode>0 OR StrIsChar(?RightChar;;NotEqualTo!;UpperCase!))
PosCharNext
Else
SelectCharNext
vSel:=StrTransform(?SelectedText;
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
"abcdefghijklmnopqrstuvwxyz")
Type(vSel)
EndIf
Endwhile
// Clean up - delete the terminator
symbol:
DeleteCharNext
Return
// Macro ends here
|
Sample
macro #7
- Like the previous macro, this macro will
convert the current word -- or everything in a selection of text
-- to lower case, including capitalized words at the beginning
of every sentence, the pronoun "I," etc. It uses a different and more efficient apporach than
Sample macro #5 above. It also should be faster than #5.
- [To copy this macro into
your WordPerfect, see here.]
// Macro begins here:
Display(Off!)
// First, if nothing is selected, select the current word:
If(?BlockActive=False)
SelectWord
Wait(10)
Endif
If(?SelectedText="") // (in case SelectWord failed
to select anything)
Display(On!)
Messagebox(;"Ooops!";"Select some text first!")
Quit
Endif
// Note: It is quicker overall
to use this command first:
ConvertCaseLowercase
// Create a temporary bookmark
to let us reselect the selection:
BookmarkCreate("Temp_Marker")
BookmarkBlock("Temp_Marker")
PosBlockTop
// Reset the Find & Replace
settings to factory default:
pResetFindReplace ()
// Set some new search and replace conditions:
SearchInSelection(Yes!)
SearchCaseSensitive(Yes!)
ReplaceWithCase (Yes!)
NotFound(Off!)
// Store search and replace
items in an array:
change[] = {
{"A";"a"};
{"B";"b"};
{"C";"c"};
{"D";"d"};
{"E";"e"};
{"F";"f"};
{"G";"g"};
{"H";"h"};
{"I";"i"};
{"J";"j"};
{"K";"k"};
{"L";"l"};
{"M";"m"};
{"N";"n"};
{"O";"o"};
{"P";"p"};
{"Q";"q"};
{"R";"r"};
{"S";"s"};
{"T";"t"};
{"U";"u"};
{"V";"v"};
{"W";"w"};
{"X";"x"};
{"Y";"y"};
{"Z";"z"}}
// Process the selection:
ForNext(i;1;change[0]/2;1)
SearchString (change[i;1])
ReplaceString (change[i;2])
BookmarkBlock("Temp_Marker")
PosBlockTop
While(True)
SearchNext()
If(?NotFound=1)
Break // (exit from this While loop)
EndIf
ReplaceWithCase (Yes!)
ReplaceCurrent
Endwhile
EndFor
// Clean up and exit:
BookmarkBlock("Temp_Marker")
PosBlockBottom
// If you want to de-select the item after it is processed
// remove the leading slash marks from the next command:
//SelectMode(Off!)
BookmarkDelete("Temp_Marker")
pResetFindReplace ()
Return
// --- Procedures here: ---
// Reset Find and Replace parameters for the Search/Replace commands:
Procedure pResetFindReplace ()
SearchString ("")
ReplaceString ("")
// Only one of these 4 Match commands can be active at any one
time:
// MatchPositionAfter ()
// MatchExtendSelection()
// MatchPositionBefore()
MatchSelection()
SearchFindWholeWordsOnly (No!)
MatchWithAttributes (No!)
ReplaceWithAttributes (No!)
SearchCaseSensitive (No!)
ReplaceWithCase (No!)
MatchWithFont (No!)
ReplaceWithFont (No!)
MatchWithFontSize (No!)
ReplaceWithFontSize (No!)
SearchInSelection (No!)
SearchWordForms (No!)
SearchWrap (No!)
MatchLimit (No!)
EndProcedure
// Macro ends here
|
|