Posts: 2,765
Threads: 138
Joined: Nov 2002
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.
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Posts: 3,522
Threads: 189
Joined: Dec 2003
Code:
press$=inkey$
if press$ then
if press$=oldpress$ then exit sub
oldpress$=press$
end if
Posts: 2,765
Threads: 138
Joined: Nov 2002
close... but i want it so if you push it down again it moves once but if you hold it down it moves once
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Posts: 3,522
Threads: 189
Joined: Dec 2003
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)
Posts: 2,765
Threads: 138
Joined: Nov 2002
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$
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Posts: 6,419
Threads: 74
Joined: Mar 2002
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.
Posts: 1,845
Threads: 44
Joined: Aug 2002
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
Posts: 2,765
Threads: 138
Joined: Nov 2002
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
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.