dosquickbasic

accepting keys without loop in quickbasic


I'm working on an program that opens up different programs for each different key inside QuickBasic 4.5 (for a game.) Unfortunately, looping more than one INKEY$ command causes it to not register most of the time.

Is there any library/method to get around this?

Here's what I put in:

DO    
IF INKEY$ = "n" GOTO 2000
IF INKEY$ = "y" GOTO 3000
IF INKEY$ = "e" GOTO 4000
LOOP

Solution

  • Something like this should work. But I suggest you start with learning how to save to variables, and you do not need GOTO in Basic, there are other ways which makes the program easier to change in the future.

    DIM KeyPressed AS STRING
    
    INPUT "Please Enter A Key (y,n,e): ", KeyPressed
    
    KeyPressed = LCASE$(KeyPressed)
    
    SELECT CASE KeyPressed
      CASE "n"
         GOTO 2000
      CASE "y"
         GOTO 3000
      CASE "e"
         GOTO 4000
    END SELECT