Board index » delphi » inkey$ in qbasic equals what in pascal?

inkey$ in qbasic equals what in pascal?

Hi,

I just started learning Pascal so I don't know much stuff yet. I was
wondering is there a equivalent function in Pascal to Qbasic's inkey$
function. ie when I prompt the user for a reply to a question like (y/n),
is there a way so that they only have to type either 'y' or 'n' without
having to press Return?

Many thanks in advance,

Kidd Rock

 

Re:inkey$ in qbasic equals what in pascal?


Quote
Alex Kidd wrote:

> Hi,

> I just started learning Pascal so I don't know much stuff yet. I was
> wondering is there a equivalent function in Pascal to Qbasic's inkey$
> function. ie when I prompt the user for a reply to a question like (y/n),
> is there a way so that they only have to type either 'y' or 'n' without
> having to press Return?

> Many thanks in advance,

> Kidd Rock

You can use the function readkey.

/Niklas Bj?rnest?l <s...@linux.nu>

Re:inkey$ in qbasic equals what in pascal?


Niklas Bjornestal schrieb:

Quote
> You can use the function readkey.

ReadKey waits for user input, Inkey$ doesn't.
Use ReadKey together with KeyPressed.

To input a key, in Basic, you write this:
do
  a$ = inkey$
loop until a$ <> ""

This would correspond to ReadKey.

However, if your code looks like this:
a$ = inkey$

then you must write, in Pascal:

uses crt;
var
  a : char;
begin
  if keypressed then a := readkey
end.

Re:inkey$ in qbasic equals what in pascal?


On Tue, 25 Aug 1998 10:12:24 +0800, "Alex Kidd" <alex_...@hotmail.com>
wrote:

Quote
>Hi,

>I just started learning Pascal so I don't know much stuff yet. I was
>wondering is there a equivalent function in Pascal to Qbasic's inkey$
>function. ie when I prompt the user for a reply to a question like (y/n),
>is there a way so that they only have to type either 'y' or 'n' without
>having to press Return?

A simple (!) example how to use readkey (untested):

var c : char;

  repeat
      c := upcase (readkey);
  until (c = 'Y') or (c = 'N');
  if c = 'Y' then ...

The function upcase simply turns y and n into Y or N.

Greetz,  Dirky

Re:inkey$ in qbasic equals what in pascal?


Quote
Frederic wrote in message <35E2823F.B438F...@primus-online.de>...
>Niklas Bjornestal schrieb:
>> You can use the function readkey.
>Use ReadKey together with KeyPressed.

Is ReadKey and KeyPressed Standard Pascal?
I got to do this assignment for school and the code has to be standard
Pascal. If they aren't Standard Pascal can I do it another way?

Thanks,

Kidd Rock

Re:inkey$ in qbasic equals what in pascal?


Alex Kidd schrieb:

Quote
> Is ReadKey and KeyPressed Standard Pascal?
> I got to do this assignment for school and the code has to be standard
> Pascal. If they aren't Standard Pascal can I do it another way?

Both belong to the unit Crt in Borland Pascal.

Re:inkey$ in qbasic equals what in pascal?


Quote
Alex Kidd wrote:

> Frederic wrote in message <35E2823F.B438F...@primus-online.de>...
> >Niklas Bjornestal schrieb:

> >> You can use the function readkey.

> >Use ReadKey together with KeyPressed.

> Is ReadKey and KeyPressed Standard Pascal?
> I got to do this assignment for school and the code has to be standard
> Pascal. If they aren't Standard Pascal can I do it another way?

There is no way to do an Inkey$, ReadKey, or KeyPressed in ISO Standard
Pascal.  Standard Pascal is about learning good, solid programming
techniques, not something as frivolous as writing programs. :)

Standard Pascal was not designed, and never intended to be, a useful
language for writing programs. Oh, BTW, there is no way you can do this
in ANSI C either, because this relies on operating system services that
you can't guarantee will be there, and it would ruin portability.

Re:inkey$ in qbasic equals what in pascal?


In standard pascal there's only readln.
Here's inkey$:

uses crt;
{...}
function inkey: string;
var c: char;
begin
    if not keypressed then inkey := '';
    c := readkey;
    if c = #0 then inkey := c + readkey else inkey := c
end;

Dirk Sudholt schrieb in Nachricht <6rtpe4$ie...@news00.btx.dtag.de>...

Quote
>On Tue, 25 Aug 1998 10:12:24 +0800, "Alex Kidd" <alex_...@hotmail.com>
>wrote:

>>Hi,

>>I just started learning Pascal so I don't know much stuff yet. I was
>>wondering is there a equivalent function in Pascal to Qbasic's inkey$
>>function. ie when I prompt the user for a reply to a question like (y/n),
>>is there a way so that they only have to type either 'y' or 'n' without
>>having to press Return?

>A simple (!) example how to use readkey (untested):

>var c : char;

>  repeat
>      c := upcase (readkey);
>  until (c = 'Y') or (c = 'N');
>  if c = 'Y' then ...

>The function upcase simply turns y and n into Y or N.

>Greetz,  Dirky

Other Threads