Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Inkey$ help
#1
I am try to make a simple program in which you move a box around the screen using the arrow keys. My problem is that i am unable to move the box at an angle, such as down-left or up-right. Does anyone know how I can accomplish this?

-I'm using Line to create my box, if that helps
Reply
#2
Well, it won't be easy (or possible, I think) using INKEY$, as that function only lets you select one key at a time. You'd have to use a keyboard handler or a library with that in it.
earn.
Reply
#3
From you post I have to assume that you can move the box up and down and side-to side?? Then moving diag. is a trivial step from here. Instead of having 4 conditions, you have 8. If I were doing it, I'd do something like this.

do
a$=inkey$
select case a$
.
.
Case up 'you have to substitute your up key here
y=y-1
case upright
x=x+1
y=y-1
.
.
.
end select

line (x,y)-(x+boxsizex, y+boxsize),,b

loop
Reply
#4
http://www.ocf.berkeley.edu/~horie/qbmkey.bas

QB Multikey Wink
am an asshole. Get used to it.
Reply
#5
I thought Berkeley was just interested in controversy?
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#6
I guess I misunderstood the original question....I now see what he was getting at.

Quote:http://www.ocf.berkeley.edu/~horie/qbmkey.bas

QB Multikey Wink

Man...this is a wierd program...I didn't even look at it...just ran it...gives really strange results. Eg, sometimes the arrow keys are inverted, sometimes not...I don't know if this is due to using Win XP DOS instead of the real deal, but...this code is unreliable for me...I'll take a close look at it later...thanks for the link to this (potentially) useful code.

Q...does this code work as advertised for anyone?
Reply
#7
Im not the smartest QB guy around but I think I can offer you a solution that is very quick. If the user taps both the up and right keys it almost appears they are moving diagonal! That is good! But it would present collision problems right? Because in all reality there just going up and over. So just make them more one or 2 pixels at a time that way the program is not to complex and the person just has to get better with there reflexes... just a thought.

And also dump the INKEY$ shit off at the next truck-stop. And at the BEGINING of every keypress loop add this:

Quote:press$ = INKEY$

It may look odd and pointless but let me assure you it will capture the keys much better... What it dose is everytime the program hits that point it changes your keypress (INKEY$) to press$ and for somereason it helps... I cannot explain it but it works.

Just to understand it run these 2 sample programs.

Quote:CLS
PRINT "Press 1 to have me say 'Yipee!!' or press 2"
PRINT "too have me say 'Bye Bye loser' ."
DO
IF INKEY$ = "1" THEN PRINT "Yipee!!": END
IF INKEY$ = "2" THEN PRINT "Bye Bye loser": END
LOOP

Stupid program, but uses keys... run it a few times and you will see sometimes you have to press 1 or 2 more than once to get the desired effect. Now run this.

Quote:CLS
PRINT "Press 1 to have me say 'Yipee!!' or press 2"
PRINT "too have me say 'Bye Bye loser' ."
DO
press$ = INKEY$
IF INKEY$ = "1" THEN PRINT "Yipee!!": END
IF INKEY$ = "2" THEN PRINT "Bye Bye loser": END
LOOP

I'm sure you will be pleased!
ey! Visit my sites:
www.angelfire.com\ex\ariesqbasic
www.ariesdomain.tk
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)