Functions and Directives

Function NextKey() Foundation

Reads the next key value from the keyboard buffer without removing it.

NextKey() --> nInkeyCode

The return value of NextKey() is an integer in the range of -47 to 422. This value identifies the key which will be taken from the keyboard buffer next. When the keyboard buffer contains no value (no key was pressed), NextKey() returns the value zero.


The function NextKey() is a compatibility function which only reads the keyboard buffer and is limited in scope. In Xbase++, the function NextAppEvent() should be used instead of NextKey() since it processes mouse events as well as keyboard events.

The function NextKey() resembles the function Inkey() and reads the next value from the keyboard buffer. It differs from Inkey(), however, because the value is not deleted but remains in the keyboard buffer. This allows testing for whether or not a key has been pressed. The processing of the key can occur at another place in the program and the key value can be removed at a later time using Inkey().

The function NextKey() provides the same values for a key press as Inkey() and LastKey(). In the header file "" symbolic constants are defined for all key values.

The operating system supports multithreading. Unlike the DOS operating system, other applications can continue running while the program waits for keyboard entry. Therefore the following control structure, which is permitted in DOS, should not be used in Xbase++:

DO WHILE (nKey := NextKey()) == 0 
   // Program code until key is pressed 

A DO WHILE loop such as this, where the keyboard buffer is read continuously, requires extensive system resources and unnecessarily delays other applications which could be running during the time when no key is being pressed.

Difference between NextKey(), Inkey() and LastKey()
// In the example two characters are written into 
// the keyboard buffer using the command KEYBOARD 
// and the differences between the functions NextKey(), 
// Inkey() and LastKey() are illustrated. 


   ? Chr( NextKey() )               // result: A 
   ? Chr( LastKey() )               // result:   (null string) 

   ? Chr( Inkey()   )               // result: A 
   ? Chr( LastKey() )               // result: A 

   ? Chr( NextKey() )               // result: B 
   ? Chr( LastKey() )               // result: A 

   ? Chr( Inkey()   )               // result: B 
   ? Chr( LastKey() )               // result: B 


If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.