When ON KBD is enabled all keystrokes are trapped and held in the keyboard buffer. KBD$ returns the keyboard buffer contents and then clears it. The buffer is also cleared by the commands: OFF KBD, ENTERKBD, INPUT, LINPUT, SCRATCH and SCRATCH A and by the RESET key. If no key was pressed or if ON KBD is disabled by OFF KBD, the string length is set to zero.
The keyboard buffer can store up to 256 characters. When the buffer is full entering more characters generates a beep and discards the character. Function keys generate 2 bytes. The first byte is 255 and the second byte specifies the function key.