QBASIC - Functions - Input
| INKEY$ | INP | INPUT$ | PEN | STICK | STRIG |
INKEY$()
k$ = INKEY$
Does not wait but gets and returns a keycode string from keyboard buffer:
len = 0 : an empty string: ""
len = 1 : ascii char: like "a"
len = 2 : extended keycode-string: CHR$(0)+CHR$(scancode)
Scancodes
F1-F10  : 59-68
F11-F12 : 133-134
Left:75, Right:77, Up:72, Down:80
>DOS BASIC: Keyboard
 
Wait for any key
WHILE INKEY$ = "": WEND
Wait for any key - get key$
DO: k$ = INKEY$: LOOP WHILE k$ = ""
L = LEN(k$)
IF L = 1 THEN PRINT ASC(k$)
IF L = 2 THEN PRINT "0 "; ASC(RIGHT$(k$, 1))
 
DO: k$ = INKEY$: LOOP WHILE k$ = ""
code = ASC(k$)
IF code = 0 THEN xcode = ASC(RIGHT$(k$, 1))
 
INP(n)
INP returns a byte read from a hardware I/O port.
Show scan codes
WHILE sc <> 1    '<esc>
  k$ = INPUT$(1) 'k$ = CHR$(0) for non-ascii keys
  sc = INP(96)   'sc = scancode
  PRINT k$, sc
WEND 
 
INPUT$()
Returns a string of characters read from the keyboard or from a specified file.
INPUT$(n[,[#]filenumber%])
n : The number of characters (bytes) to read.
filenumber% : The number of an open file.
If filenumber% is omitted, INPUT$ reads n keystrokes from the keyboard.
>statement: INPUT
 
keyboard
All keys return 1 char: all non-ascii keys return '0' - the second char is discarded.
No screen echo! Not terminated by 'enter'
Wait for one key
k$ = INPUT$(1) ' = CHR$(0) for non-ascii keys
[sc = INP(96)  ' = scancode for the key]
Input blind string
pw$ = "xyz"
PRINT "Tast Password"
s$ = INPUT$(3)
IF s$ = pw$ THEN PRINT "OK" ELSE PRINT "no-no"
file
 
PEN()
x
STICK()
x
STRIG()
x