Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
read keys once then check if it's held
#1
Ok... first

this doesn't work
Code:
press$ = INKEY$
IF press$ = oldpress$ THEN EXIT SUB
oldpress$ = press$

any reason why?
I'm trying to get it if you hold the key down it does go running away. you have to push it down once each time.
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#2
Code:
press$=inkey$
if press$ then
if press$=oldpress$ then exit sub
oldpress$=press$
end if
Reply
#3
close... but i want it so if you push it down again it moves once but if you hold it down it moves once
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#4
It can't be done, not by using Inkey$ atlest.

Code:
CLS


DO
press$ = INKEY$

IF press$ = "a" THEN a& = a& + 1 ELSE b& = b& + 1

LOCATE 1, 1: PRINT a&; b&;

LOOP

Try that, as you can see, b& always increases, even if you hold a.
So there is no good way of telling if the key is being pressed or not as Inkey$ returns chr0 anyways (in betveen the rate of repetition set in bios/windows)
Reply
#5
no if you add this
Code:
t = TIMER
DO: LOOP UNTIL TIMER - t > .01


anyways....



preedit: i just added the timer and now it works like i want it to?
Code:
t = TIMER
DO: LOOP UNTIL TIMER - t > .01

press$ = INKEY$
IF press$ = oldpress$ THEN EXIT SUB
oldpress$ = press$
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#6
I've always done it with flags, one per direction. If key pressed: If flag not set move, set flag. If key not pressed: unset flag.

This works better with a custom keyboard handler, of course.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#7
You could also check out INP(&H60), it already has some kind of flag system in it. Check this learning example:
Code:
DO
   Scan% = INP(&H60)
   IF Scan% <= 127 THEN PRINT "Key"; Scan%; " is being pressed" ELSE PRINT "Key"; Scan% - 128;" is being released"
LOOP UNTIL Scan% = 1
Reply
#8
hmmm i tried some sort of flag system didn't work though




Code:
press$ = INKEY$
IF LEN(press$) THEN
IF press$ = oldpress$ THEN
  IF held = 0 THEN
   held = 1
  ELSE
   EXIT SUB
  END IF
ELSE
  held = 0
END IF
oldpress$ = press$
END IF
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)