beautypg.com

Crunch CRiSP File Editor 6 User Manual

Page 89

background image

Page 89

Scan Codes

As described above, CRiSP uses a set of key definitions which allow you to create macros which are not
dependent on the keyboard and system you are using. You do this by using key names such as
. These key names are translated into key codes. Some keys on the keyboard, notably the
keypad and cursor keys are duplicates. (Technically they are not duplicates; whether they are duplicates or
not depends on the application or keyboard bindings you have in effect).

To make life easier, when you specify certain keynames, both physical keys on the keyboard are treated
together and identically. Thus, you do not need to set up duplicate bindings for the Cursor-Left-Arrow and
Keypad-Left-Arrow keys.

Sometimes this can be just the wrong thing to do. For example, the EDT editor under Digital's VAX/VMS
system sets different bindings to the cursor keys and the keypad keys.

CRiSP has an emulator for EDT mode, and in order to work, it relies on using the underlying physical scan
codes to make key bindings. Normally, you would use the assign_to_key macro and specify a set of key
names and macros to bind to the keys. This is not sufficient to distinguish between the cursor and keypad
keys. To get around this problem, CRiSP allows you to access the scan codes generated by the underlying
system to distinguish similar keys. This is accomplished with the assign_to_raw_key macro.

In general, it is advisable to avoid raw key (scan) codes. For examples, the scan codes available under
Microsoft Windows are different to the Unix X windows keyboards. In addition, under X Windows, different
vendors assign different scan codes to different keyboards, so any attempt to use scan codes is liable to
result in failure when operating on different hardware and/or platforms. The CRiSP/EDT emulation has a
learning mode dialog to train CRiSP so that the emulation can know the difference between different
keystrokes.

In order to use the scan codes, you first need to know what the scan code is for each key. To do this you
need to use the read_char() and inq_raw_kbd_char() primitives (or consult the crisp.log debug output).
You then need to convert these scan codes to decimal and use the notation:

"#nnnn"

in the assign_to_raw_key() macro.

Creating Keyboards and keyboard stacks

When CRiSP starts up, there is a default minimalist keyboard defined. This is virtually useless, but acts as a
place holder for the user specific key bindings to be loaded into.

The assign_to_key() macro is used to set up bindings for keys, so that CRiSP knows which macro to
execute when you press a key.

Sometimes it is desirable to create a private keyboard which has a restricted set of function keys defined.
For example, the various character mode popup menus create a popup window on the screen and provide
limited key bindings in a controlled fashion, such as , , etc. Rather than hide
all the default key bindings, a new keyboard is created which overrides the current global one.

This is done via the keyboard_push() primitive. This creates a brand new keyboard, which has no key
bindings in it and saves the previous global keyboard on a stack for later retrieval. Having called
keyboard_push you can now call assign_to_key without affecting the existing global key assignments.

When you are finished with the keyboard, you call keyboard_pop to discard the keyboard and throw away
all the key bindings you have made. The keyboard_pop primitive takes an optional integer argument. By
default the keyboard is discarded, but you can specify a value which does not discard the keyboard, but
simply removes the keyboard from the current list of keyboards to be scanned when a key is pressed.

This allows you to create a keyboard, for instance in the main() part of your macro, and keep it to one side
until needed, e.g. when you popup a window.

Various primitives are available for populating a keyboard:

copy_keyboard

This allows you to copy bindings from another keyboard into the current one. For instance, you
might want to copy the macros which are assigned to the arrow keys. This would allow your macro
to use the users preferential arrow keys, e.g. if they are using vi or CUA mode.

keyboard_typeables