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

243 INKEY input the number of the key pressed Purpose This function waits for a specified time while constantly testing to see if a key has been pressed on the keyboard. If a key is pressed before the time runs out then the ASCII value of the key is given. If no key is pressed in the given time then -1 is returned and the program continues. See the keyword ASC for an explanation of ASCII values. Note that a key can be pressed at any time before INKEY is used. All keys pressed are stored in a buffer in the computer and a character is removed from the buffer by, for example, the INPUT statement.

You can clear the buffer of all characters by giving the command *FX 15,1 The number in parenthesis, after the word INKEY , gives the amount of time that the computer must wait before giving up. The time is given in hundredths of a second, and may have any value between 0 and 32767. In addition, the function INKEY can be used to see if a key is actually pressed at the instant the function is called. Normally pressing a key once enters the code for that key into the keyboard buffer. If the key is kept down then it will normally auto-repeat and further characters will be entered into the buffer.

However, when the buffer is read with INPUT or GET or INKEY , you will have no idea how long the character has been waiting in the buffer. An alternative statement is provided which actually tests the keyboard rather than the buffer. INKEY with a negative number in the parenthesis, eg INKEY(-27) will enable you to test to see whether a particular key is pressed at that instant. The number in parenthesis determines which key you wish to test. The following table shows the negative number to be used to test any particular key. Thus the letter L would be tested with PRINT INKEY (-87) . Examples 100 keynumber=INKEY(5) 220 result=INKEY(Y) X=INKEY(100)