Crunch CRiSP File Editor 6 User Manual
Page 88

Page 88
keyboard. When you press a key, CRiSP looks at the current buffer and looks to see if a local keyboard has
been defined for this buffer. If so, it checks the local keyboard to determine if the current key stroke has a
macro binding. If one is found then the associated macro is invoked.
If the local keyboard isn't defined, or if the local keyboard does not contain a binding for the current
keystroke, then CRiSP looks at the global keyboard. If no key binding is stored in the global keyboard, then
the key press is effectively ignored.
This local vs. global behaviour allows you to set up a standard set of key bindings which apply to all buffers
but to occasionally define a private local keyboard depending on the buffer.
For example, this mechanism is used by the template mechanism, so that certain keys can be intercepted,
e.g.
Keys and Keystrokes
CRiSP internally uses a 32-bit code for each key on the keyboard. These 32-bit keycodes are sufficient to
allow every key on the keyboard to be encoded and also to handle the modifier keys, such as Shift, Ctrl, Alt
etc. It is possible to examine these key encodings, but usually it is best to avoid them where possible, since
CRiSP provides a high level machine independent way to specify key names. (If you want to know more
about the key encoding mechanism, then look at the include file src/crunch/include/keycode.h ).
In most of the macros and documentation, you will see key name specified inside angle brackets, e.g.
underlying key encodings. These key names are used by various macros, such as assign_to_key and allow
composite keys to be specified, such as
Nowadays, most keyboards conform to the standard PC-101 keyboard layout so there is very little variation
in the look and feel of any physical keyboard, although some Unix systems do ship with slightly non-
standard keyboards.
By using the naming convention, your macros are portable from one environment to another. This is
especially useful if you are working in a Unix environment with different vendors keyboards, as the
underlying internal codings are different.
As mentioned above, CRiSP uses a 32-bit internal coding for keys. When you specify a keyname, such as
converting between the numeric keycodes and the string version (key_to_int and int_to_key). The
read_char() macro primitive can be used to read a single keystroke from the user, but it returns an integer
value. You can use the above functions to convert to and from the key names.
Character based terminals
In the character based version of CRiSP, life is not as clear cut as it is for the GUI versions when it comes to
defining keystrokes. Although CRiSP still provides the various mechanisms documented here for assigning
macros to keystrokes, the definition of a keystroke is a little more hazy.
A character based terminal normally contains all the keys you would use in a GUI environment. For
example, in an X Windows environment, you use the same keyboard for GUI applications as you do for a
terminal command window (e.g. an xterm window). However a character based terminal is limited in the
keys that can be identified by an application. Normally it is not possible to determine, for instance that Alt-B
has been pressed. More than likely the application (terminal emulator) will see the letter b or B but totally
ignore the Alt key modifier.
Most terminal emulators are configurable and allow you to program the sequence of characters sent to the
application for each key pressed. The default settings are usually of those to emulate a VT-100 style
keyboard which is insufficient for CRiSP as it needs access to more keys.
In order to handle the full range of keys on the keyboard, escape sequences are usually used to signal
specific keys on the keyboard. For instance, when you press the Up-Arrow key, three characters are sent to
CRiSP:
In order for CRiSP to know that these three keys represent the single keystroke
tell CRiSP about these escape sequences.
This is done using the set_term_characters macro primitive. CRiSP comes with a set of terminal specific
keyboard mappings for various popular terminals. See the macros in the src/crunch/tty directory for
examples of this.