The meaning of the codes

Before we can understand the use of the flags and the masks we have to know what the various fields in the hex codes stand for. The meaning of the different fields may depend on what other fields look like, so it isn't entirely trivial. Each byte of the key code (eight bits or two hexadecimal digits) is treated separately.

byte 3 (leftmost) :

This byte contains bits that indicate the status keys. In addition three bits have been reserved for special flags that can be controlled by the user. The bits are:

bit 0
right shift key (hex code of byte is 01)
bit 1
left shift key (hex code of byte is 02)
bit 2
Control key (hex code of byte is 04)
bit 3
Alternate key (hex code of byte is 08)
bit 4
Caps Lock key (hex code of byte is 10)
bit 5 - 7
User flag 1 to 3 respectively.

A combination of status keys results in the sum of their codes. For example, if both the Alternate key and the left shift key were pressed, the value of byte 3 becomes 0A or 10 in decimal notation. The best way to become familiar with these bit patterns is to try out the Ctrl-K command with various key combinations.

byte 2 :

This byte contains either a flag to indicate that we have a mouse event, or it contains masking information. If the 0 bit (hex code 01) is set we have a mouse event and more bits may be set. In the UNIX version of stedi however the mouse is currently not supported. The masks are explained in the part about flags and masks. For the next two bytes we assume now that the mouse bit is off.

byte 1 :

Contents are in hexadecimal:

0
Byte 0 contains a character to be put in the text.
1
Byte 0 contains the ASCII code of the corresponding alternate key code. So 0141 is Alt-A as 41 is the ASCII code of the character A.
2
Byte 0 contains the ASCII code of the corresponding control key code. Unlike regular control combinations stedi takes them apart and stores them as a control bit and an ASCII character. On systems that don't support the combination of a digit and the control key such combinations can be generated with the alt-function key combination.
4
Byte 0 contains the number of a function key, counting from 1 up (so F1 is 0401).
8
Byte 0 contains the number of a function key, but in addition a shift key was pressed.
C
Byte 0 contains the number of a function key, when both a shift and the control key were also pressed. On systems that don't support such key combinations this code is given by the Ctrl-Function key combination.
10
Byte 0 contains the code for a special key or key combination. This may involve the arrow keys, the delete key, the backspace, the return and enter keys and more.
1E
Byte 0 should be zero. The `endcommand' code.
1F
Byte 0 should be zero. This establishes a direct connection to the command line. The keys following are used to build up a command for the command line that is executed after the `endcommand' code (see under 30). This `endcommand' code must be part of the same key redefinition. The command thus formed will not be put in the command history.
20
Byte 0 contains the ASCII code of a key in the numeric key pad. This information isn't really used by stedi.

byte 0 (rightmost) :

This byte contains either the ASCII code of a key or a simulated ASCII code. It is a `real' ASCII code if byte 1 is zero.

Although only the key codes as explained above can be returned from the keyboard, the editor knows a few more codes internally. These codes cannot possibly come from the keyboard so stedi can use them for signal passing. Some of these codes are:

08FF0000
Inactive key. Code is given as for instance a sequence with several keys at the left hand side gives no match. Its only effect is that the message `Key not active' is placed in the message line.
10000000
STARTUP code. A lhs with this code makes that its right hand side is executed at startup, after the command tail has been interpreted and its files have been read. The code isn't executed when the editor is run in stream mode. In the right hand side this codes is a good `null' code in the sense that it has absolutely no effect, not even a message.
12000000
AFTER_READ code: When a file is read into a buffer this code is put into an input buffer that is read before the next user input is processed. This can be used for instance to call a macro that studies the extension of the name of the file just read and to take corresponding action.
18000000
ON_EXIT code: special left hand side of which the right hand side is to be executed when the editor is left.
x4000000
Absolute setting of the flags field. x is an even hexadecimal digit.