Contents / Part 3 / Previous chapter / Next chapter / Index


25 Programming the User Defined function keys

At the top of the keyboard is a group of special red keys which are called User Defined Keys. Instead of producing a fixed character the user can 'define' these keys to generate any character or string of characters that is required. For example, to set up key f1 so that it produces the word PRINT every time it is pressed you can type

*KEY 1 PRINT RETURN

To set key f2 to produce the word DATA you enter

*KEY 2 DATA RETURN

If you want to enter more than one word into a User Defined Key then you can enclose the words in inverted commas

*KEY 3 "IF X=" RETURN

though quote marks are not necessary.

When you are developing programs it is very useful to have one of the keys set up to change to MODE7 and then LIST the program automatically. If you were typing in the commands MODE 7 and LIST you would normally follow each with a RETURN, and you have to include something equivalent to press the RETURN key when you set the key up. In fact you enter this to set up key f0

*KEY 0 MODE 7 |M LIST |M

The two characters | and M together are understood to mean the same thing as pressing the RETURN key. In fact the | in front of any letter makes the computer generate a control character. You may remember that to enter "paging mode", where the

computer stops at the bottom of every page, you can type CTRL N. That instruction can be added to the key f0 redefinition as well, if you wish.

*KEY 0 MODE 7 |M |N LIST|M

It is important to remember that any *KEY definition must be the last statement on a line because since the computer finds a * at the start of a statement it passes the whole of the rest of the line to the Machine Operating System and not to BASIC. The Machine Operating System does not understand : which BASIC would understand as a multiple statement separator. The same thing applies to *FX statements - only one is allowed per line.

However, it is acceptable to use colons to separate statements within the key definition. For example

*KEY 6 MOVE 0,0 : DRAW X,Y |M

If you want to you can set up the user defined keys in a program in exactly the same way that they are set up in command mode.

Thus

10 *KEY 7 "|B LIST|M |C"

would let key 7 turn the printer on, list the program and then turn the printer off.

If you wish to include an ASCII code greater than 128 (&80) then you can do this by using, the sequence |! to add 128 to the value produced. For example:

*KEY 8 "|!|V"

would put a single "character" in key 8 and the ASCII value of the character would be made up from the two parts. The |! is worth 128 and the ASCII value of CTRL V is 22, giving a total value of 150.

The BREAK key

Pressing the BREAK key causes a "soft reset" which does not reset the clack or clear the definitions of the user defined keys. However, pressing BREAK while the CTRL key is pressed will cause a "hard reset" which resets everything. This feature is implemented from release 1.0 of the operating system. Pressing BREAK and SHIFT together will be used in future to "auto-boot" the machine so that the computer loads and runs a program without any further instructions.

As you know, when you press the BREAK key the computer is reset and nothing can change that. Your program will stop and all variables will be lost; even your program will appear to be lost. However, there are a number of things that can be done to alter the course of events.

First, a program can be recovered by typing, OLD RETURN and then RUN RETURN. Alternatively, the BREAK key can

be 'redefined' by using the expression

*KEY 10 "OLD |M RUN |M"

which treats the BREAK as another user-definable key.

Other keys

The arrow and COPY keys can also be redefined - they can be considered to be user defined keys 11 to 15 (see also pages 424 and 441).

Exit: BBC Microcomputer User Guide; Kasoft Typesetting; Archer


The BBC Microcomputer User Guide was written by John Coll and edited by David Allen for the British Broadcasting Corporation.

Optical character recognition and original formatting effort by Mark Usher.

HTML version maintained by: Kade "Archer" Hansson; e-mail: archer@dialix.com.au

Last updated: Monday 12th February 2001