heeeelp! the beep dont stop!

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
User avatar
bongomeno
Veteran
Posts: 266
Joined: Wed Dec 10, 2008 9:08 am
Location: Arizona
Contact:

heeeelp! the beep dont stop!

Post by bongomeno »

hello qbworld! i am having some trouble with some games im working on. i am using inp(96) for input in the game, but after i press a few keys in the game, it starts beeping after every key i press! how do i fix this?!?! :(
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Clear the keyboard buffer: A$ = INKEY$

In the keyboard read loop.

After so many presses, the keyboard buffer gets full. INP(&H60) only reads the presses. It does not clear them.

Let me know if you need a multi-key routine to press more than one key at a time.

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
User avatar
bongomeno
Veteran
Posts: 266
Joined: Wed Dec 10, 2008 9:08 am
Location: Arizona
Contact:

heeeelp! the beep dont stop!

Post by bongomeno »

umm... i kinda need that multi key routine too. lol thanx
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Code: Select all

'Multi-key. Uses arrow keys, but can use any others you need. 
'Just find the scancodes needed.SC array holds keys pressed only.

DEFINT A-Z
 DIM BG(300), Box(300), SC(127)
       'DEMO code
 SCREEN 13   'graphic coordinates are 0 to 319 wide and 199 deep.
 COLOR 4: LOCATE 10, 5: PRINT "Multikey Keyboard input routine"
 COLOR 10: LOCATE 12, 4: PRINT "Use the arrow keys to move the box."
 LOCATE 13, 4: PRINT "Note that you can press two or more"
 LOCATE 14, 4: PRINT "keys at once for diagonal movement!"
 COLOR 14: LOCATE 16, 4: PRINT " Also demonstrates how GET and PUT "
 LOCATE 17, 4: PRINT "are used to preserve the background."
 COLOR 11: LOCATE 19, 11: PRINT "Press [Esc] to quit"

 X = 150: Y = 50: PX = X: PY = Y

 GET (X, Y)-(X + 15, Y + 15), BG  'GET original BG at start position
 LINE (X, Y)-(X + 15, Y + 15), 9, BF 'draw sprite (box)
 GET (X, Y)-(X + 15, Y + 15), Box   'GET to Box Array
 
 DO  'main game loop
   Start! = TIMER
   DO WHILE Start! + .05 > TIMER      '(1/18th second) Multikey scancode loop  
     IF Start! > TIMER THEN Start! = Start! - 86400  'midnite correction  
     I = INP(&H60)     ' Get keyboard scan code from port 96   
     I$ = INKEY$       ' clear the keyboard buffer so no beeps  
     IF I < 128 THEN SC(I) = 1 ELSE SC(I - 128) = 0   'place true/false values into array        
   LOOP      

   PX = X: PY = Y  'previous coordinates
   IF SC(75) = 1 THEN X = X - 5: IF X < 0 THEN X = 0  'change position if valid
   IF SC(77) = 1 THEN X = X + 5: IF X > 304 THEN X = 304 
   IF SC(72) = 1 THEN Y = Y - 5: IF Y <0> 184 THEN Y = 184  
   IF SC(80) = 1 THEN Y = Y + 5: IF Y > 184 THEN Y = 184 
   IF X <> PX OR Y <> PY THEN             'look for a changed coordinate value
      'following code keeps the background from changing in graphic sprite games! 
     PUT (PX, PY), BG, PSET               'replace previous BG first
     GET (X, Y)-(X + 15, Y + 15), BG      'GET BG at new position before box is set
     PUT (X, Y), Box, PSET                'PUT box image at new position
   END IF
 LOOP UNTIL SC(1) = 1 'loop until [Esc] (scan code 1) is pressed

SYSTEM 'end program

NOTE: If you are using ASCII moves or Screen 0, use text positioning. PUT and GET will not work in Screen 0! You have to check the text positions are within the Screen mode boundaries before a move also.

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Post Reply