strange behaviour of readkey...or not

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

strange behaviour of readkey...or not

Darius Blaszyk
Hi there,

I have a console app that reads keys being pressed and then does some
action. In short it would be like this:

repeat
  if fileage(myfile) <> imyfile then
  begin
    writeln('file changed');
    imyfile := fileage(myfile);
  end;

  ch := readkey;
until ch = 'q'

So what I want is that the fileage test is done continously and when a user
presses a key some other procedure is executed. But the problem is that when
"ch := readkey" is reached, the app seems to stay waiting until a key is
pressed. In other words it only does the fileage test when I press a key
other than q. In my example the fileage test is only done once.

Am I under the wrong impression that I should pull it off using readkey??
What is the alternative??

Darius Blaszijk


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: strange behaviour of readkey...or not

Florian Klaempfl-2
Darius Blaszijk wrote:

> Hi there,
>
> I have a console app that reads keys being pressed and then does some
> action. In short it would be like this:
>
> repeat
>   if fileage(myfile) <> imyfile then
>   begin
>     writeln('file changed');
>     imyfile := fileage(myfile);
>   end;
>
>   ch := readkey;
> until ch = 'q'
>
> So what I want is that the fileage test is done continously and when a user
> presses a key some other procedure is executed. But the problem is that when
> "ch := readkey" is reached, the app seems to stay waiting until a key is
> pressed. In other words it only does the fileage test when I press a key
> other than q. In my example the fileage test is only done once.
>
> Am I under the wrong impression that I should pull it off using readkey??
> What is the alternative??

Do check of keypressed first:
http://www.freepascal.org/docs-html/rtl/crt/keypressed.html

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: strange behaviour of readkey...or not

Darius Blaszyk
Florian,

Thanks. I have fixed it using:

    if KeyPressed then
      ch := ReadKey
    else
      ch := '';

I know I should have know better, but for some strange reason only readkey
in a previous version seemed to work just fine. Thats why I was confused.

Darius Blaszijk

----- Original Message -----
From: "Florian Klaempfl" <[hidden email]>
To: "FPC-Pascal users discussions" <[hidden email]>
Sent: Monday, June 20, 2005 7:37 PM
Subject: Re: [fpc-pascal] strange behaviour of readkey...or not


> Darius Blaszijk wrote:
>
> > Hi there,
> >
> > I have a console app that reads keys being pressed and then does some
> > action. In short it would be like this:
> >
> > repeat
> >   if fileage(myfile) <> imyfile then
> >   begin
> >     writeln('file changed');
> >     imyfile := fileage(myfile);
> >   end;
> >
> >   ch := readkey;
> > until ch = 'q'
> >
> > So what I want is that the fileage test is done continously and when a
user
> > presses a key some other procedure is executed. But the problem is that
when
> > "ch := readkey" is reached, the app seems to stay waiting until a key is
> > pressed. In other words it only does the fileage test when I press a key
> > other than q. In my example the fileage test is only done once.
> >
> > Am I under the wrong impression that I should pull it off using
readkey??
> > What is the alternative??
>
> Do check of keypressed first:
> http://www.freepascal.org/docs-html/rtl/crt/keypressed.html
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Freepascal Advocate Store

L505
In reply to this post by Florian Klaempfl-2
Are there any I Love Freepascal t-shirts, hats, coffee mugs, etc.?

Love,
Lars

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Freepascal Advocate Store

Florian Klaempfl-2
L505 wrote:

> Are there any I Love Freepascal t-shirts, hats, coffee mugs, etc.?

Afaik not.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Freepascal Advocate Store

Lance Boyle
Make your own without leaving your computer: www.t-shirts.com.

Lance


On Jun 23, 2005, at 1:42 PM, Florian Klaempfl wrote:

> L505 wrote:
>
>
>> Are there any I Love Freepascal t-shirts, hats, coffee mugs, etc.?
>>
>
> Afaik not.
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Freepascal Advocate Store

Vincent Snijders
In reply to this post by Florian Klaempfl-2
Florian Klaempfl wrote:
> L505 wrote:
>
>> Are there any I Love Freepascal t-shirts, hats, coffee mugs, etc.?
>
>
> Afaik not.

Not exactly Freepascal, but it has a familiar cheetah:
http://www.cafepress.com/miraclec

Vincent.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal