INKEY$ function

Purpose:

INKEY$ returns a string containing the character for the key pressed.

Syntax:

RetStr = INKEY$

Return Value:

  • Data type: STRING
    RetStr string containing the character for the key pressed.

Parameters:

  • None.

Remarks: INKEY$ does not wait for keyboard input and does not automatically echo to the screen.

Example:

CLS

PRINT "Press a key to stop TIME$."


WHILE INKEY$ = ""
  LOCATE 2, 1, 0
  PRINT TIME$
WEND

INKEY function

Purpose:

INKEY returns a value corresponding to the key combination pressed.

👉 Because the INKEY function uses device-dependent values generated by the keyboard hardware/software for return of some of the key presses, consistent values cannot be assured across various hardware/software configurations.

Also, on some systems, because mouse and keyboard handlers are tied together in Windows, INKEY will return values when the mouse is moving over an active window.

Syntax:

RetVal = INKEY

Return Value:

  • Data type: INTEGER
    RetVal
    • Alphanumeric keys return the Windows Code Page code point value of the character corresponding to the key pressed.
    • Ctrl + alpha keys return (ASCIIcode - 96).
    • Alt + alphanumeric keys return (Scancode + 1000).
    • Alt + enhanced keys return (Scancode + 1000) * -1.
    • Ctrl + enhanced keys return (Scancode + 2000) * -1.
    • The Extended keys listed below, typically, return
       BackSpace :   8
       Home      : -71
       End       : -79
       PageUp    : -73
       PageDown  : -81
       Insert    : -82
       Delete    : -83
      
      Cursor keys:
       Up        : -72
       Down      : -80
       Left      : -75
       Right     : -77
      
      Function keys:
       F1        : -59
       F2        : -60
       F3        : -61
       F4        : -62
       F5        : -63
       F6        : -64
       F7        : -65
       F8        : -66
       F9        : -67
       F10       : -68
      

    Parameters:

    • None.

Remarks:

👉 Unlike INKEY$, INKEY does wait for keyboard input but does not automatically echo to the screen.

See the KEYPRESS for another BCX function that waits for keyboard input.

Example 1:

Use the following program to determine which number is generated by

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

Example 2:

DIM A%
RANDOMIZE(TIMER)
CLS

DO
  LOCATE 1,1
  PRINT "Press Esc or Enter";
  PRINT RND
  LOCATE 1, 30
  A% = INKEY

  IF A% = 27 THEN
    LOCATE 2, 1
    PRINT "This arbitrary randomness must end !"
    EXIT DO
  END IF

  IF A% = 13 THEN
    LOCATE 2, 1
    PRINT "Jumping into DaSub"
    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

LCLICK function

Purpose:

LCLICK returns TRUE, if the left mouse button has been pressed; FALSE, if the left mouse button has not been pressed.

Syntax:

RetVal = LCLICK

Return Value:

  • Data type: INTEGER
    RetVal TRUE, if the left mouse button has been pressed; FALSE, if the left mouse button has not been pressed.

Parameters:

  • None.

Remarks:

LCLICK is SWAPBUTTON aware.


Example Here is a simple console example. Tune your guitar!:

Here is a simple console example. Tune your guitar!

WHILE NOT LCLICK     ' loop until a left mouse button click is detected 
  Beep( 82.41, 1500) ' E (6th string):  82.41 Hz (E2) 
  Beep(110.00, 1500) ' A (5th string): 110.00 Hz (A2) 
  Beep(146.83, 1500) ' D (4th string): 146.83 Hz (D3) 
  Beep(196.00, 1500) ' G (3rd string): 196.00 Hz (G3) 
  Beep(246.94, 1500) ' B (2nd string): 246.94 Hz (B3) 
  Beep(329.63, 1500) ' E (1st string): 329.63 Hz (E4) 
WEND

RCLICK function

Purpose:

RCLICK returns TRUE, if the right mouse button has been pressed; FALSE, if the right mouse button has not been pressed.

Syntax:

RetVal = RCLICK

Return Value:

  • Data type: INTEGER
    RetVal TRUE, if the right mouse button has been pressed; FALSE, if the right mouse button has not been pressed

Parameters:

  • None.

Remarks:

RCLICK is SWAPBUTTON aware.

ExampleClick here to go to example.:

Click here to go to example.