INPUT @ |
![]() ![]() ![]() |
The INPUT @ statement enables entry of data from the keyboard at a specific screen position or from previously stored DATA statements.
Format
INPUT @(x, y) {,} {:} var {, length} {_} {:} {format} {modes} {THEN statement(s)} {ELSE statement(s)}
where
The comma after the cursor position is optional and has no effect on the operation of the statement.
The optional THEN and ELSE clauses used with TIMEOUT allow a program to determine whether the input timed out. Successful input executes the THEN clause. A timeout will execute the ELSE clause.
The INPUT @ statement reads data from the DATA queue or, if there is no stored data, from the keyboard.
Keyboard Input
When reading from the keyboard, the current prompt character will be displayed to the left of the given input position. No prompt is displayed if the input column position, x, is zero or if the prompt has been disabled using the PROMPT statement. The prompt character will be removed from the screen on completion of the input.
If the colon character before var is present, the original contents or var are displayed in the input area and entry commences in overlay mode. If the colon character before var is not present, entry commences in insert mode with a blank field.
The user has three options:
The values stored for printing characters are the ASCII characters associated with the key. Non-printing characters result in stored character values as listed under Character Values for Terminal Input.
If no length expression is included, data characters are stored until the return key is pressed.
If length is specified, up to that number of characters may be entered after which input is automatically terminated as though the return key had been pressed, any subsequent key entries being retained for the next INPUT statement. The return key is not stored as part of the input data.
The INPUT @ statement may not behave correctly if the length of the input field causes it to extend over multiple lines and the terminal in use does not automatically wrap from one line to the next when displaying long text output.
The optional underscore component of the statement suppresses the automatic input termination when length characters have been entered. Any number of characters may be entered but only length characters will be displayed.
The optional colon causes the carriage return and line feed output when the return key is used or on reaching the input length limit to be suppressed.
In all cases, the following editing keys are available.
These editing keys can be modified using the KEYEDIT statement.
When the return key is pressed to terminate input, if a format is specified, the data is redisplayed using this mask to apply format rules such as right justification.
DATA Queue Input
Where the data queue is not empty, the INPUT @ statement reads the item at the head of this queue, copying it verbatim to var with no processing of any embedded control characters. The length expression is ignored. The item is displayed as though it had been typed.
Use of the STATUS() function after an INPUT @ statement returns zero unless input was terminated by a key defined using the KEYEXIT or KEYTRAP statements.
Use of Pipes
QM recognises input from pipes as a special case. Programs that process data from a pipe can read the data using the same QMBasic statements and functions as for keyboard input. If the end of the data is reached, a subsequent INPUT @ will return a null string. The STATUS() function will return ER$EOF.
Examples
DISPLAY @(0,10) : "Account " : PROMPT "" INPUT @(8, 10) : ACCOUNT.NO, 16
This program fragment displays the current value of ACCOUNT.NO with a suitable annotation and accepts input. Pressing the RETURN key alone will retain the original value as displayed. The PROMPT statement has been used to suppress display of the prompt character.
INPUT @(10, 5) : PRICE, 10 '10R'
This program fragment inputs a value for the PRICE variable, redisplaying it right justified on completion of input.
See also: |