Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use 2+ keys at once to do 2+ thing at once 2

Status
Not open for further replies.

Icaerus

Programmer
Dec 18, 2002
2
0
0
US
I'm writing a top down scroller I would like to use the up arrow and the left arrow to make my sprite go diagonal.
I already know how CHAR numbers but I can only use one at a time my code:

PRESS$=INKEY$
IF PRESS$= CHR$(116) THEN GOSUB FORWARD
IF PRESS$= CHR$(71) THEN GOSUB BACK
IF PRESS$= CHR$(70) THEN GOSUB LEFT
IF PRESS$= CHR$(73) THEN GOSUB RIGHT
(Also this setup is very laggy it takes a second to respond)
any help would be great.
 
I noticed that too, but not in the original coding, it only started to happen after I added some more code, It must do something to it. You can fix it by when you turn the keyboard function on simply saying kbmatrix%(42) = 0 in the sub onkb, it fixes the problem.
 
when you run the code by itself, it runs very fast. when you add more code to it (a game) i find that multi-key routines seem to stick a bit (at least pure qb....) maybe because it takes so long to loop again or something...
 
Pure QB multikey routines will stick in an intensive program because it will miss one of the key release scan codes when two keys are released almost simultaneously.

Speaking of scan codes, I figured out where my problem is. The arrow keys are rather unusual: they send an extended key scan code (E0) in addition to the normal code, but they also constantly send left Shift press and release scan codes. Turning NumLock on (or holding Shift) makes it stop doing that, but I'm not sure how to turn NumLock on and off within the program, because POKE(1047), PEEK(1047) OR 32 doesn't work after onkb is called.
 
Any extra code slows a program down, the code that you added is what is making the program slower. The multikey routine doesn't stick at all, its designed specifically not to.

If the arrow keys are doing strange things then is it possible to use the numeric keypad? There you not only can use up, down, left, and right, but also the octo-cardinal directions.
 
DPhrygian, try toggling the numlock. I can almost guarantee that it should fix many problems.
 
Yes, as I said in my second post, turning numlock on fixes the problem (or I can just use the numpad keys, either way). Thanks for the response (that goes for qbking as well!)

Incidentally, I'm wondering whether there's a way to turn numlock on (via QB, I mean) using the ASM keyhandler. The usual method of POKEing 1047 apparently doesn't work once the keyhandler has been called, and just forcing the numlock key to be pressed (with a statement like kbmatrix%(69) = 1) won't actually turn numlock on.

But again, it's not really a big deal, since the user can just use the numpad keys or turn numlock on himself.
 
The keyboard handler that I posted only tells you which key is pressed, not the state of it. Meaning it makes no disguishment between a and A if caps lock is on or and up arrow and an 8 if num lock is on.

But you can determine if it is on or not by using PEEK 1047.
IF PEEK 1047 = <on> THEN key$ = &quot;8&quot; ELSE key$ = &quot;up arrow&quot;


Not having used the numlock in a long time I don't know which pattern tells you if it is on or off.
 
Just turn it off before you activate the handler. Put it in the init routine for it even. :)
 
There are two reasons to use buffers. One way is to use a block of RAM to store a bit of memory from a file from quicker access.
Or the type of buffer used here is for quicker memory &quot;dumps&quot; it is easier to more large amount of memory around.
 
This seems to be a popular toppic again... (lets see if it will float to the top again... from like the 5th page...)

Have Fun, Be Young... Code BASIC
-Josh

cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top