Acorn Computers BBC Micro Model B w/8271 — Acorn BBC Micro Model B w/8271 User Guide Manual PDF

70 12 GET, INKEY Sometimes it is useful to be able to detect a key as soon as it is pressed without having to wait for the RETURN key to be pressed. For example most games react immediately when a key is pressed. There are a group of four functions which respond to single keystrokes. GET GET$ INKEY INKEY$ The GET and GET$ functions wait until a key is pressed; the INKEY and INKEY$ pair give up after a while if no key is pressed. 100 A$ = GET$ will wait (for ever) until a key is pressed but 100 A$ = INKEY$(200) will wait for only two seconds (200 hundredths of a second). If no key is pressed within two seconds then the computer will move on to the next line of the program and will be empty.

If a key was pressed after say one second then the computer will immediately move on to the next line of the program and will put the character typed into . 100 PRINT "DO YOU WANT TO GO ON" 110 PRINT "YOU HAVE 2 SECONDS TO REPLY" 120 A$=INKEY$(200) 130 IF A$="" THEN PRINT "TOO LATE YOU MISSED IT" 140 IF A$="Y" THEN PRINT "COURAGEOUS FOOL!" 150 IF A$="N" THEN PRINT "COWARD" One of the most common uses of GET$ is to wait at the bottom of a page for the user to press any key when he or she is ready to go on.

100 A$ = GET$ GET and INKEY are very similar to GET$ and INKEY$ but instead of returning a character which can be put into a string variable they return a number which is the ASCII code of the character. The ASCII code of ‘Y’ is 89 and the ASCII code of ‘N’ is 78, so the last program could be re-written as