★ APPLICATIONS ★ DIVERS ★ FUNCTION KEY LISTER (COMPUTING WITH THE AMSTRAD) ★ |
Function Key Lister (Computing With the Amstrad) | Applications Divers |
YOU'VE probably always taken it for granted that when you press the A key on your Amstrad you get the letter A reflected on your screen. However, as this article shows, it ain't necessarily so. You can arrange things so that pressing the A will give you B, C or whatever. Confusing as this seems, it's actually quite useful. The point is that each key in the Amstrad has its own unique number, in the range 0 to 79. This number simply labels the key switch - not the letter that happens to be printed on it. It has to be like this to allow for the keys that are duplicated, such as the digits 0-9. How else could the Amstrad tell which of the two number 5s had been pressed for instance? Fine, but how does the Amstrad know what to interpret the key press as? Well, it maintains a table to help it keep track - and when you switch on it defaults to the normal state of affairs, where pressing a key with the A marked on it is interpreted as A. In actual fact our normal A key has the number 69 associated with it and, provided we haven't done anything clever, the Amstrad will look up 69 and see that it's linked with 65. 65? Yes, because that's the Ascii for A - remember that the Amstrad likes numbers, not letters. So our table links the key switch numbers with the Ascii code we want it to be interpreted as. Why not label it as 65 in the first place, you may ask? Well, getting our characters in this way has three advantages:
The code produced by a particular key when pressed is quite easily altered. If for some reason you wanted the A key to produce the letter B when pressed then: KEY DEF 69,1,66would tell the Amstrad to produce the Ascii code 66 when key number 69 is pressed. The 1 indicates that the key is to auto repeat if held down. Zero would disable this feature. Extra codes can be tagged on to the end of the command to indicate which code is to be produced if Shift or Ctrl is held down at the same time. The codes 128 to 159 have a special significance. The Amstrad stores 32 strings, one for each of these codes. When one of these special codes is produced it is removed from the keyboard buffer and replaced with the whole string. The keys producing these codes are called function keys. To set up a function key to produce a string we use KEY. for instance: KEY 128,"MODE 1"+CHR$(13)As you can see, any string expression can be used. When the code 128 is encountered it is expanded into the full string. Any key can be defined to produce the codes using KEY DEF. On power up, or after a reset, the keys on the numeric keypad to the right of the main keyboard produce codes 128 to 140. You'll have to use KEY DEF to redefine some of the other keys on the keyboard to produce the rest of the function key codes. Although there are 32 strings, the Amstrad only reserves 120 bytes of memory. This will not be enough if all the keys are to be defined, or if long strings are to be used. Fortunately the function key buffer - the memory where the strings are stored - can be any size and anywhere in memory. It can only be relocated from machine code though. LD DE,address |
|
|