FutureBasic Logo

<<    Index    >> FutureBasic 5

inkey$   function

stringVar$ = inkey$

This function tests whether there is a keypress event pending in the event queue (this happens if the user has pressed a key and no program statement has yet detected it). If there is such an event on the queue, inkey$ removes the event from the queue and returns a 1-character string indicating what key was pressed. If there is no keypress event pending, inkey$ returns a null (zero-length) string.
Note that inkey$ is a rather old-fashioned way to check for keypresses. It will not work reliably if your program calls HandleEvents regularly, because HandleEvents also checks for keypress events and removes them from the event queue. If your program uses HandleEvents, then you should check for keypresses either by trapping the _evKeyDIALOG event (if there are no active editable text fields in the current window or if you are running in the Appearance Compliant runtime).

The pressed key character is not automatically displayed on the screen. Use the print statement if you want to display the character.
The value returned by inkey$ is affected by whether the Shift key, Option key, etc. were down. However, these "modifier" keys will not generate any keypress event by themselves; they must be pressed in combination with some character key in order for inkey$ to detect the keypress. If you want to detect whether a certain modifier key was down when an event happened, use the event% function (or the _evtMeta field of the event record). If you want to detect whether a modifier key is currently down, use the Toolbox function GetKeys.

See Also:
HandleEvents; dialog function; tekey$ function; on dialog