#

## macro

Define or print a key or button macro binding.

### Usage:

> macro [window_type] [option] [key [value]]

> > where key is the name of a valid key (see below), and value is a magic command-line command. If present, window_type must be one of the known valid window types accepted by the specialopen command (color, netlist, and wind3d), or a known layout tool (box, wiring, nettool, or pick). If omitted, the layout window is assumed by default, unless the command has been called from inside a window (using the colon or semicolon escape to the command-line), in which case that window type is assumed.

> > In the non-Tcl version of magic, the window_type must be one of the three valid window types listed above, or layout. Tool button bindings are hard-coded, fixed, and unknown to the macro handler.

> > In the Tcl version of magic, tool types are generated by procedure and can be modified or overridden. The four tools listed above are the default tools known to magic. If no window or tool type is given, then the current tool in the current active layout window is assumed.

> > option may be one of the following:

> > list [-reverse]
> >   The key bindings are returned in the form of a Tcl list (Tcl version of magic only). The returned value is a single list with alternating entries of the macro key and the macro binding. In Tcl, this list can be treated as a dictionary type of key:value pairs. With the -reverse option, the keys and values are reversed, resulting in a dictionary that can be searched or listed by function.
> > help
> >   Curently, macro help is equivalent to macro without arguments, and returns a full list of macro names and their bindings.
> > search text
> >   Return only results which match (all or in part) the string text. For example, macro search grid will return all key bindings that include the command grid.
> > copy tool_name
> >   This is a method introduced to allow the interactive creation of new tools, in the Tcl version of magic. Each tool is defined specifically by its unique button and key bindings. Because tools generally keep most of the same default bindings, the copy option will copy all the existing bindings to the new tool from the current tool. This can be followed by switching to the new tool and replacing macros with ones unique to the tool.

### Summary:

> The macro command translates keystrokes typed into a layout window into magic command-line commands. When the key key is pressed in a layout window, the command stored in value is executed relative to that layout window. The default bindings are specified in the system `.magic` file, read at startup. These macros may be arbitrarily rebound using the macro command.

> A key macro may be unbound from a command by passing an empty string ("") for the value.

> key is any valid name for a keyboard keypress event. In its simplest form, this may just be the name of the key, such as "g" or "X". The space bar key must be quoted in double-quotes; most other characters may be unquoted. Control characters may be specified by the two-character combination of the carat ("^") key followed by a capital letter, such as "^Z". The use of embedded control characters is deprecated, as it is incompatible with Tcl syntax.

> key may also be specified as any valid X11 name for a key as defined in the include file `keysymdef.h` on UNIX systems. This allows specification of function keys such as "XK_F8" or keypad keys such as "XK_KP_Right".

> Buttons are treated just like keys for the purpose of defining macros. While the official names for buttons in `keysymdef.h` are "XK_Pointer_Button_1", etc., the macro command accepts the abbreviated forms Button1, and so forth.

> Finally, key modifiers may be prepended to the key name. Valid key modifiers are Shift_, Control_, Alt_, and Meta_, and may be coupled in any combination. Mouse buttons may also be combined with key modifiers, so, for example, Shift_Button1 is a legal, unique binding.

### Implementation Notes:

> macro is implemented as a built-in window command in magic.

### See Also:

> imacro
> tool (Tcl version)

Return to command index

Last updated: March 7, 2020 at 1:06pm