'===========================================================================
' Subject: GET INPUT                          Date: 11-06-95 (15:39)       
'  Author: Justin Pasher/Vadim Kilshteyn      Code: QB, QBasic, PDS        
'  Origin: FidoNet QUIK_BAS Echo            Packet: KEYBOARD.ABC
'===========================================================================
'Here's a nifty little code to get input from a user. It'll check every
'key pressed to a verification string that you define. You can also
'define the keys to end the input. The sub returns a key code = to the
'ASC() of the key used to end the input. It'll also return a string of
'the input. One neat affect is that it allows screen "wrapping". Try
'defining a StrLeng value greater than the screen width. It's cool. This
'was coded by Vadim Kilshteyn and me. Enjoy..

DECLARE FUNCTION GetInput$ (ReturnStr$, Row, Col, StrLeng, WhatChar, Cursor, DoSound, StrCRC$, RetCRC$, MaxCol)
  DIM SHARED Nul AS STRING * 1
  DIM SHARED Esc AS STRING * 1
  DIM SHARED Enter AS STRING * 1
  Nul = CHR$(0): Enter = CHR$(13): Esc = CHR$(27)
  CONST True  = -1
  CONST False = 0
  CLS
  PRINT "Kewl Typing Program"
  FOR Ver = 1 TO 254
    IF Ver <> 7 AND Ver <> 27 THEN StrCRC$ = StrCRC$ + CHR$(Ver)
  NEXT
  RetCRC$ = Enter + Esc
  Row = 3: Col = 11
  WhatChar$ = "ù"
  LOCATE 3, 1: PRINT "Password ["; TAB(20); "]"
  Returned$ = GetInput$(RetStr$, Row, Col, 20, ASC(WhatChar$), True, True, StrCRC$, RetCRC$, 19)
  LOCATE 4, 1
  IF Returned$ = CHR$(27) THEN PRINT "Aborted..." ELSE PRINT RetStr$
  IF LEN(Returned$) = 1 THEN PRINT "Return Code: "; Returned$ ELSE PRINT "Return code: CHR$(0) +"; Returned$

FUNCTION GetInput$ (ReturnStr$, Row, Col, StrLeng, WhatChar, Cursor, DoSound, StrCRC$, RetCRC$, MaxCol)
  IF WhatChar = 0 OR WhatChar = 8 OR WhatChar = 9 OR WhatChar = 10 OR WhatChar = 11 OR WhatChar = 255 THEN WhatChar = 32
  IF Cursor = True THEN Cursor = 1 ELSE Cursor = 0
  CurX = Col
  CurY = Row
  ScrnFull = 1
  IF MaxCol - Col + 1 <= StrLeng THEN
    SpaceC$ = STRING$(MaxCol - Col + 1, WhatChar)
    Total = MaxCol - CurX + 1
  ELSE
    SpaceC$ = STRING$(StrLeng, WhatChar)
    Total = StrLeng
  END IF
  MaxScrn = INT(StrLeng / Total)
  StartX = Col
  LOCATE Row, Col: PRINT SpaceC$;
  LOCATE Row, Col, Cursor

GetKey:
  Key$ = ""
DO UNTIL LEN(Key$)
  Key$ = INKEY$
LOOP

  IF INSTR(1, RetCRC$, Key$) = False AND INSTR(1, StrCRC$, Key$) = False THEN GOTO GetKey
  IF INSTR(1, RetCRC$, Key$) > 0 THEN GOTO EndIt
  IF Key$ = CHR$(25) THEN
    LOCATE CurY, StartX
    ScrnFull = 1
    Word$ = ""
    PRINT SpaceC$
    CurX = StartX
    LOCATE CurY, CurX
    GOTO GetKey
  END IF
  IF Key$ = CHR$(3) THEN GOTO GetKey
  IF Key$ = CHR$(0) + CHR$(144) THEN GOTO GetKey

IF LEN(Word$) = StrLeng AND Key$ <> CHR$(13) AND Key$ <> CHR$(8) THEN
  IF DoSound = True THEN SOUND 450, 1: SOUND 950, 1
  GOTO GetKey
END IF

IF Key$ = CHR$(8) THEN
  IF LEN(Word$) = 0 THEN
    CurX = StartX
    LOCATE CurY, CurX
    IF DoSound = True THEN SOUND 450, 1: SOUND 950, 1
    GOTO GetKey
  END IF
  IF CurX = StartX + 1 AND ScrnFull > 1 THEN
    ScrnFull = ScrnFull - 1
    CurX = StartX
    LOCATE CurY, StartX
    'PRINT SpaceC$
    Word$ = LEFT$(Word$, LEN(Word$) - 1)
    LOCATE CurY, CurX
    PRINT MID$(Word$, Total * (ScrnFull - 1) + 1, Total);
    CurX = MaxCol + 1
    LOCATE , CurX
    GOTO GetKey
  END IF
  CurX = CurX - 1
  LOCATE CurY, CurX
  PRINT CHR$(WhatChar);
  LOCATE CurY, CurX
  Word$ = LEFT$(Word$, LEN(Word$) - 1)
  GOTO GetKey
END IF
  IF CurX > MaxCol THEN
    CurX = StartX
    LOCATE CurY, StartX
    PRINT SpaceC$;
    LOCATE , StartX
    ScrnFull = ScrnFull + 1
  END IF
  LOCATE CurY, CurX: PRINT Key$;
  CurX = CurX + 1
  LOCATE CurY, CurX
  Word$ = Word$ + Key$
  GOTO GetKey
EndIt:
  ReturnStr$ = Word$
  GetInput$ = Key$
END FUNCTION
