Home | Tips | Library | Other Authors | Other WP Sites | Writer's Links | Contact | Site Map | Donate |
Barry
MacDonnell's Toolbox for WordPerfect |
||
Macros, tips, and
templates for Corel®
WordPerfect® for Windows® |
Page
updated Aug 30, 2019 |
|
WordPerfect
Tips Main tips page | Browse more tips |
||
"Two-tap"
macros
- how to press a keyboard key twice in succession to perform a
task, play another macro, etc. Related pages - Two-key macros - First press a shortcut key to play the macro, then press another alphanumeric key to perform some task or action. 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.). |
Since a few standard keyboard keys are relatively unused by most people, a small macro can be assigned to them with little impact on your productivity. One press (tap) of the key to which the macro was assigned causes it to type the character into the document, as usual. But two sequential presses (double tap) of the key causes the macro to perform some other task — including, if desired, the task of playing another macro. Below are some sample macros that make use of the backward single quote ( ` ) key (located above the Tab key and to the left of the "1" key). You could as easily use, for example, the backslash ( \ ) key instead, by replacing the ( ` ) character where it appears (twice) in each of the sample macros. Tips ☼ To copy macro code like these samples
into your WordPerfect to turn them into functioning macros, see here.
☼ Insted of using the same alphanumeric key twice in succession you can use one shortcut key combination to start a special macro, then imediately press another key to perform some action — e.g., <Ctrl+K+Q> or <Alt+D+2>. See "two key" macros here. ☼ To create a macro that uses three (or more) sequential key presses (e.g., a "three-tap" macro), see (for example) the HRt+Save.wcm macro here. The particular sample
macros below always
enter
(type) a text character in the document when you play them (then they
immediately delete that character when the key is tapped again).
This means the macros will modify the document when they type the character, thereby removing the "(unmodified)" label from the program's title bar — as expected. In particular, since the first macro simply centers the cursor location vertically on screen, you should explain the document modification aspect of these macros to others who use them and who will then be faced (on exit) with a dialog asking them if they want to save the modified document. This can be disconcerting if it is unexpected. Sample macro 1 This macro centers the current cursor location vertically on your screen. It does this by re-positioning both the insertion cursor and the surrounding text vertically on the screen using a pair of Quickmark and Display commands. This helps you see the context of the material at the cursor's location. The macro should be assigned to the ( ` ) key (the key just above the Tab key and to the left of the "1" key). [Note that this particular key is listed in WordPerfect's Keyboard Shortcuts dialog only when you enable that dialog's option, "Allow assignment of character keys." This brings up a separate list of just character keys. The ( ` ) character is listed just under the underscore ( _ ) character.] // Macro code begins If(?Substructure or ?GraphicSelected) Return Endif If (?LeftChar="`") // if a ` character is on the left - DeleteCharPrevious // - delete the character QuickmarkSet // - then center the cursor location vertically: Display(On!) QuickmarkFind Display(Off!) BookmarkDelete("QuickMark") Else Type ("`") // - type a ` character Endif Return // Macro code ends Tip: If you want to use a similar technique but without double-tapping (or use the technique as part of another macro): // Macro code begins If (?Substructure or ?GraphicSelected) Return Endif QuickmarkSet Display(On!) QuickmarkFind Display(Off!) BookmarkDelete ("QuickMark") Return // Macro code ends Of course, if you use this code as part of another macro you will need to decide if you need to test for the cursor's location inside a substructure or a selected graphic (the If..Endif commands), as well as where the macro should Return to when the code is executed. Sample macro 2 This macro plays another macro. The macro is "chained" to another macro with a simple command, so that when it is assigned to a key and that key is double tapped, the second macro will execute. This might be handy to play some macros that do relatively simple — and frequently needed — editing or formatting tasks. The macro should be assigned to the ( ` ) key (the key just above the Tab key and to the left of the "1" key). [Note that this particular key is listed in WordPerfect's Keyboard Shortcuts dialog only when you enable that dialog's option, "Allow assignment of character keys." This brings up a separate list of just character keys. The ( ` ) character is listed just under the underscore ( _ ) character.] Be sure to replace the <macroname.wcm> text placeholder (but retain the double quotes) in the MacroFileChain() command below with the name of the actual macro you wish to play. Put both macros — this one and the one to be played — in your default macro folder, shown in your Tools, Settings, Files, Merge/Macro (tab). This is where this macro will look for the macro to be played (using the ?PathMacros command. Do not rename the macro to be played unless you also rename it in the MacroFileChain() command. // Macro code begins OnError(End@) If (?LeftChar="`") // if a ` character is on the left - DeleteCharPrevious // - delete the character MacroFileChain(?PathMacros + "<macrorname.wcm>") Else Type ("`") // - type a ` character Endif Label(End@) Return // Macro code ends Sample macro 3 This macro changes multiple spaces at the cursor location into a Tab. Suppose you want to use the ` key (to the left of the 1 key on most keyboards) to play a macro that (1) deletes all multiple spaces at the cursor location and (2) replaces them with a tab. This is sometimes needed when you copy material from another source and the paragraph indentations are made up of spaces, not tabs. Suppose also that you want to be able to use this key to type a ` character whenever it might be needed. In other words, you do not want to lose the functionality of the ` key. Copy the code below and save it in your macros folder, then assign the macro to the ` key — just to the left of the "1" key on the top row of your keyboard — using the procedure described in the "How to..." sections above. [When you get to the Keyboard Shortcuts list in Step 2 above, you must enable (i.e., tick) the "Allow assignment of character keys" checkbox to change the list to the alphanumeric key list. Scroll down in that list. The ` key item is located just above the left brace ( { ) in the list.] Note again that the macro uses — is assigned to — the ` key on your keyboard. Thereafter, pressing the ` key once will type a ` character, as usual. Pressing it twice consecutively will cause the first ` characer to be "seen" by the macro on the left of the cursor, whereupon it will delete it and play the "working" part of the macro (i.e., convert the spaces to a tab) instead of simply typing another ` character. // Macro begins here - If (?LeftChar="`") // if a ` character is on the left - DeleteCharPrevious // - delete the character // The "working" part of the macro begins here - vCount:=0 // - initialize a counter // While the left character is a space, move to the left - While (?LeftChar=" ") PosCharPrevious Endwhile // Start selecting text - SelectMode (On!) // While the right character is a space, move right - While (?RightChar=" ") PosCharNext vCount:=vCount+1 // - increment counter Endwhile // If there's more than one space, delete all of them - If (vCount>1) SelectDelete Tab // - then insert a Left Tab Else SelectMode (Off!) // - turn select mode off Endif // The "working" part of the macro ends here Else Type ("`") // - type a ` character Endif Quit // Macro ends here Tips You can directly download this macro as 2Key-S2T.zip. It also contains optional code to search for all multiple spaces and replace them with tabs; you can use this code as a standalone macro. You can create "triple-strike" or even "quadruple-strike" macros by having
the macro assigned to the alphanumeric key check the number of
instances of that character that appear to the left of the last
instance. If (for a triple-strike macro) the character appears two
times, then the third press of the key would cause the two characters
to be deleted and the macro to execute other commands. This approach
increases the number of ordinary alphanumeric keys that might make good
candidates to use to play such a macro. See "Make
a key do 'double duty'..." for examples.
|
|
|