Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2005-06

strange behaviour of readkey...or not

7 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Darius Blaszijk

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

Reply by email

Florian Klaempfl
to Darius Blaszijk
Darius Blaszijk wrote 23 lines
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

Reply by email

Darius Blaszijk
to Florian Klaempfl

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

Earlier message 42 lines
----- Original Message ----- From: "Florian Klaempfl" To: "FPC-Pascal users discussions" 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 - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email