|
- Written and documented by David Deley
Introduction to CMac Chapter 11: Defining a key to run a macro
Test code is provided below as an attachment.)
Let's say we have a macro, such as the one we made in
Introduction to CMAC. 2: Hello World II,
and we're tired of running it via MACRO -> RUN... or clicking the
toolbar button, and then typing in the name of the macro to run. We'd
like to assign a key to run the macro. We can do this as follows:
Go to TOOLS -> CUSTOMIZE, set the left side to "General" (at the top):
Click on the "Keys/Commands..." button. Then scroll down to the
bottom to the section "User-defined Operations" and click to highlight
"User Macros":
Click "Insert" and fill in the fields as follows:
NAME: whatever you want to name it.
COMMAND LINE: mycmac^testhello
('mycmac' is the name of the .MAC file containing the macro 'testhello'. See
Introduction to CMAC. 2: Hello World II for more info.)
TYPE: set to MACRO (See below for other options)
PRIMARY KEY: To set the primary key click the
button to the right of the Primary Key field, then press the key you
want to define. (In this example, I set the Primary Key field to CTRL-Z
by holding the CTRL key down and pressing the Z key.)
Click OK when finished. You may get a message that CTRL-Z is
already assigned to a different command (in our case CTRL-Z happens to
already be assigned to the 'Undo' function). This is OK. Since we
inserted our new command at the end of the Command Mapping list (under
"User-defined Operations") our definition of the CTRL-Z key will
supersede any definition of the key made above in the Command Mapping
list. The last key definition in the list is what the key ends up
being. Also, if we later decide to change our primary key to something
else besides CTRL-Z, or delete our primary key definition, CTRL-Z will
then revert back to its previous definition of 'Undo' as defined
earlier in the Command Mapping list.
Now when you enter CTRL-Z the words "Hello World" will be entered into your current window as if you typed them in.
-----------------------------------------------------------
OTHER OPTIONS FOR TYPE
'Type' can also be set to any of the following:
PROGRAM: Set 'Command Line' to
the path and name of a .exe program you want to run. Enclose the entire
path\filename in double quotes if there is a space in the path or
filename.
HELP_FILE: Set 'Command Line'
to the index title of a help topic in the Multi-Edit online help. For
example, you could set the command line to "Using Regular Expressions"
(without the quotes).
TEXT FILE: Set 'Command Line' to the path and name of a text file you want to load.
Enclose the entire path\filename in double quotes if there is a space in the path or filename. (Tech details: Command_Line gets passed to routine LdFiles in
macro MeSys.s . On entry MParm_Str= "/CW=1/FN=Command_Line". You can add other
qualifiers accepted by LdFiles to the end of Command_Line.)
COMMAND: The documentation
says, "This option must be selected for Multi-Edit to recognize that
the command line refers to an internal Multi-Edit macro command."
Internal Multi-Edit macro commands are apparently identified by number.
To see what's available I suggest looking at the Command Map Report
(See Introduction to CMAC. 6: Command Map Report)
Look down the column labeled "T" (I think for Type), look for the
number 5. Under the "Cursor Movement" heading there are a number of
5's. Then look for the corresponding number under the "Cmd" column (the
last column). For example, "Cursor Down" is Multi-Edit internal command
# 4, and "Cursor Up" is Multi-Edit internal command # 1.
So if you select COMMAND as the type, you could set 'Command Line'
to the number 4, assign a key, and that key will perform a "Cursor
Down" (what is normally assigned to the down arrow key).
MODE SHIFT: This is if you want
to define a key sequence, such as keypad 7 followed by keypad 4. Here's
an example. Below is the EDX keypad layout (available as an add-on, see
Smooth Scroll, Scroll Margins, Editing Keypad (EDX) ):
| Code: |
EDX-MODE KEYPAD KEY FUNCTIONS
+-------------------------------------------+
| Num Lock |/ | * |- |
| | | Find next| Del L |
| |
| Find | Und L |
|----------+----------+----------+----------|
|7 |8
|9 |+
|
| GOLD | Sect
| |
|
| | Swap
| |
|
|----------+----------+----------+ |
|4 |5
|6 |
|
| Advance | Backup | Cut | Del W |
| Bottom | Top | Paste | Und W |
|----------+----------+----------+----------|
|1 |2
|3 |
|
| Word | EOL | Char | Enter |
|Changecase| Del EOL | Specins | |
|---------------------+----------| |
|0
|. |
|
| Line | Select | |
| Open Line | Reset | |
+-------------------------------------------+
+----------+
|6 |
| Cut | <-- key function
| Paste | <-- GOLD key function
+----------+
keypad key
|
In this example the keypad 7 key is defined as the "GOLD Key" which
performs a mode shift. To get the GOLD key function you first press the
GOLD key (keypad 7) then press the key you want.
For example, if you press the GOLD (keypad 7) key followed by the
keypad 6 key, you get a "paste" operation, whereas if you just pressed
the keypad 6 key without first pressing the GOLD key it performs a
"cut" operation.
Another example, if you press the GOLD (keypad 7) key followed by
the keypad 4 key, the cursor will move to the end of the file (bottom).
Or if you press the GOLD (keypad 7) key followed by the keypad 5 key,
the cursor will move to the beginning of the file (top).
[We used to print these words on sticky paper, cut out the words,
and affix the words to the front of the keys themselves. We would
highlight the lower word indicating it was the GOLD key function while
leaving the top word unhighlighted. That way our users could look at
the keys themselves to see what functions the keys performed. The
yellow highlighting is is probably where the idea of calling the mode
shift key the GOLD key came from.]
To define the keypad 7 key as a mode shift key:
Click "Insert" to insert a new command as we did above and fill in the fields as follows:
NAME: GOLD Key
COMMAND LINE: 207
(Here you choose any number you want other than 0. This is the mode
shift number we are shifting to. It doesn't matter what number you
choose. EDX uses 207, which is a number I just made up at random, so
don't use 207 unless you want to intergrate with the EDX add-on
package.)
TYPE: set to MODE SHIFT
PRIMARY KEY: To set the primary key click the
button to the right of the Primary Key field, then press the key you
want to define. For our example, set the Primary Key field to the
Keypad 7 key (which will show up as "Num 7").
Mode: Leave this be with a 0 in it.
Reset Mode (box): Leave Unchecked.
Click OK when finished. This defines the keypad 7 key to be the
mode shift "GOLD" key. When you press the keypad 7 key the words "GOLD
Key" will show up in the message area at the lower left of the
Multi-Edit screen.
Now to define the keypad 4 key to be "move cursor to end of file"
after the GOLD key is pressed, click "Insert" to insert a new command
as we did above and fill in the fields as follows:
NAME: End of File
COMMAND LINE: 10
(10 happens to be the Multi-Edit internal command number which
moves the cursor to the end of the file. We must set Type to COMMAND
for this to work.)
TYPE: set to COMMAND
PRIMARY KEY: To set the primary key click the
button to the right of the Primary Key field, then press the key you
want to define. For our example, set the Primary Key field to the
Keypad 4 key (which will show up as "Num 4").
Mode: 207
(This is where we put the mode number we shifted to via the GOLD
key defined above. This means this key is defined for mode 207. (The
usual default mode is 0.) )
Reset Mode (box): Checked.
Thus pressing the key will complete the mode shift key sequence and return us back to the default mode 0.
Click OK when finished.
Now the key sequence Keypad 7 followed by Keypad 4 will move the cursor to the end of the file.
What happens if you accidentally press the GOLD key (keypad 7) and
decide you didn't want it? The user needs a way to cancel the mode
shift. I suggest defining the GOLD key so if you press it a second time
it will cancel the mode shift. This gives the user a way out. Click
"Insert" to insert a new command as we did above and fill in the fields
as follows:
NAME: Cancel Gold Key
COMMAND LINE: 0
(Return to mode 0)
TYPE: set to MODE SHIFT
PRIMARY KEY: To set the primary key click the
button to the right of the Primary Key field, then press the key you
want to define. For our example, set the Primary Key field to the
Keypad 7 key (which will show up as "Num 7").
Mode: 207
(This is where we put the mode number we shifted to via the GOLD
key defined above. This means this key is defined for mode 207. (The
usual default mode is 0.) )
Reset Mode (box): Checked.
Thus pressing the key will complete the mode shift key sequence and return us back to the default mode 0.
Click OK when finished.
Now the key sequence Keypad 7 followed by Keypad 7 again will
cancel the mode shift. The words "Cancel GOLD Key" will show up in the
message area at the bottom left of the Multi-Edit screen.
See Smooth Scroll, Scroll Margins, Editing Keypad (EDX)
for an example. You can temporarily install the add-on package, then
take a look at the commands it defines, then uninstall the package if
you don't want to keep it.
RELATED ARTICLES:
Introduction to CMAC. 1: Hello World
Introduction to CMAC. 2: Hello World II
Introduction to CMAC. 6: Command Map Report
Smooth Scroll, Scroll Margins, Editing Keypad (EDX)
|