Page 1 of 1
heeeelp! the beep dont stop!
Posted: Wed Feb 25, 2009 2:18 pm
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?!?!
Posted: Wed Feb 25, 2009 3:53 pm
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
heeeelp! the beep dont stop!
Posted: Wed Feb 25, 2009 4:50 pm
by bongomeno
oh sweet! thanx for the help.
heeeelp! the beep dont stop!
Posted: Wed Feb 25, 2009 5:13 pm
by bongomeno
umm... i kinda need that multi key routine too. lol thanx
Posted: Wed Feb 25, 2009 5:45 pm
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