INKEY$ function
Purpose: INKEY$ returns the ASCII character for the key pressed.
Syntax: RetStr$ = INKEY$ Parameters:
|
Remarks: INKEY$ does not wait for keyboard input and does not automatically echo to the screen. See the KEYPRESS for a function that waits for keyboard input.
INKEY function
Purpose: INKEY returns a value corresponding to the key combination pressed.
Syntax: RetVal% = INKEY Parameters:
|
Note : INKEY does wait for keyboard input but does not automatically echo to the screen.
Use the following program to determine which number is generated by what keystrokes on your computer.
DIM a% CLS PRINT "Press keys to see their key codes." PRINT "Press Esc to quit" WHILE a% <> 27 a% = INKEY IF a% <> 0 THEN LOCATE 3, 4 PRINT " " LOCATE 3, 4 PRINT a% END IF WEND
Here is a sample program that uses the INKEY function
DIM A% RANDOMIZE(TIMER) CLS DO LOCATE 1,1 PRINT "Press Esc or Enter "; PRINT RND A% = INKEY IF A% = 27 THEN PRINT "This arbitrary randomness must end !" EXIT LOOP END IF IF A% = 13 THEN PRINT "Jumping to Subroutine" CALL DaSub() END IF LOOP PRINT "You are no longer in the loop." SUB DaSub() STATIC Cnt% Cnt% = Cnt% + 1 PRINT "Added one more to the pile" PRINT "Pile is now " & STR$(Cnt%) END SUB