Specifications

Event Multitasking - 9
A=KEYPAD$(1)
returns the key position number to a numeric variable. A zero is returned if no key was pressed. For
large keypads, the legends often contain some words and symbols in addition to letters. The variation
is most suited for these cases.
Assigning Character String to Keys
A table in RAM can be programmed to return any ASCII value. The table is set up so that the first character is the
upper–left–hand corner and the last character is the lower–right–hand corner.
You can assign a single character string to the keys in the following manner.
10 FOR X=0 TO 15
20 READ A$
30 POKE SYS(8)+X,ASC(A$)
40 NEXT
50 DATA 1,2,3,A,4,5,6,B,7,8,9,C,*,0,#,D
This example matches the KP–1 Keypad except that the "#" sign is replaced by a carriage return (value=13).
Applications Examples
Basic 16–Key Example
The first example is written for the KP–1 Keypad. No characters were entered into RAM. The CAMBASIC system
defaults to the KP–1 character set.
10 'Basic 16 Key Demo Program
40 ON KEYPAD$ GOSUB ..Key_interrupt
50 GOTO 50
60 ..Key_interrupt
70 PRINT KEYPAD$(0)
80 RETURN
Line 40 tells CAMBASIC to call a subroutine by the name of “Keypad_interrupt” every time a key is
pressed.
Line 50 is used only as part of this demo program so that the system will wait. You could insert the
rest of your control program.
Line 70 prints the keypad character.
Line 80 returns program execution to the place that it was executing before the key was pressed.
Inputting Multi–digit Numbers
The basic examples print out the key that was pressed. The following example is a variation of the basic 16–key demo that
inputs a multi–digit number.
10 'Input a multi–digit number
30 ON KEYPAD$ GOSUB ..Key_interrupt
35 PRINT R
40 DELAY .25
45 GOTO 35
50 ..Key_interrupt