• 0

qbasic + arrow keys


Question

3 answers to this question

Recommended Posts

  • 0

ive worked out how to do it-

keyin$=inkey$

if len(keyin$) = 2 then keyin$= right$(keyin$,2)

because it returns NUL and another ASCII.

and as to your second question, i was planning to use C++ with allegro......but i cant compile it properly 9see other thread)

  • 0

Wow, it's been a while since QBasic. And don't worry, we know what a fun toy QBasic is, even though it's limited...

I just looked up my old QBasic code on my ancient Win95 laptop:

One way I read arrow keys:

read$=right$(lcase$(inkey$),1)
select case(read$)
case chr$(27): system
REM                           the "esc" key to exit
case "h":
REM                           "up" arrow
case "k":
REM                           "left" arrow
case "m":
REM                           "right" arrow
case "p":
REM                           "down" arrow
end select

How did I find out these values? I just ran this program:

do
c$=inkey$
select case(c$)
case "q": exit
case "":
REM so it doesn't print 'null', and you can see your output
case else: print c$;
end select
loop

I usually made a function called "readkeys" which just contained the call to inkey$ with formatting as above, so "readkeys$" was global throughout the program, but I forget how.

Another way I read keys: I found this snippet of code in a file by itself:

_arrow.bas
KEY 15   CHR$(128)+CHR$(&H48)
KEY 16   CHR$(128)+CHR$(&H4B)
KEY 17   CHR$(128)+CHR$(&H4D)
KEY 18   CHR$(128)+CHR$(&H50)

so I must have defined the arrow keys as user-defined keys, and then I guess I used "ON_KEY(15)"...etc... to do direct key reads? But that's all I can figure out!

We're talking ten years ago, from files originally run on a 486er. Now, I'm running Red Hat Linux 9.0 on an AMD 1000 machine I built myself, and I only code in C.

So, you understand, reading my QBasic code is like it was written by someone else; if I hadn't written comments, I'd have no clue, now!

Incidentally, when you're ready to work in C, I *highly* recomend using Linux and the gcc command-line compiler, and editing in emacs. Believe it or not, it makes C just as easy to use as QBasic, without all that "Visual" garbage getting in the way!

Yes, it will be difficult to learn, but you get frustrated sometimes learning QBasic, right? You'll be treated to the same frustration in C that you've grown to love, but you'll have a much wider base of programmers who know about what you're doing, and in the end you'll have a language that can actually DO something!

Also, C in Linux CAN do terminal/character operations and "raster" graphics just like QBasic, it's just a matter of using the right library (ncurses and vga, respectively).

A note to everybody else:

If you're going " What the heck? This is 2005! QBasic is how Amish people program! ", you just haven't seen how QBasic grew up. The QB4.5 edition came with it's own compiler; you could create .exe files just like in C. QBasic also shed it's line numbers and gotos and added functions and seperate subroutines, and even a base of library functions! In this way, it teases you along for a while with object-oriented-like abilities without actually giving you objects. Add to this that you could catenate strings just by a$=a$+b$+c$ and draw lines with LINE(x1,y1)-(x2,y2) and you can see where QBasic is attractive if you just want to write a simple, small executable. For anything more complicated than a screen hack or text-based game, however, it's too small.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.