Re: KeyPressed

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

Re: KeyPressed

Lowell C. Savage
"Tomas Hajny" wrote, in part:

> > I'm running an old DOS (originally compiled with TP) Pascal program that
> > uses the CRT unit.  It has several places where it uses KeyPressed/ReadKey
> > to pause a screen until the user responds.  It uses the same combination
> > to
> > read user input.  However, it appears to be a random function which
> > determines whether (or when?) a key is detected.
> >
> > For instance, when the program begins, it sets up the screen, (clears,
> > displays a title at the top, and displays some initial messages, then uses
> > "KeyPressed/ReadKey" to clear the keyboard buffer. then displays a "Press
> > any key to continue:" prompt and waits for a successful "KeyPressed"
> > (using
> > "REPEAT UNTIL KeyPressed;" and then discards the return from the following
> > ReadKey.
> >
> > The trouble is that after that "Press any key to continue" prompt comes
> > up,
> > I may need to press anywhere from 1 to 10 keys to get the "KeyPressed"
> > routine to see it.  (I inserted logging statements between each line of
> > code.)
> >
> > Any ideas?  (Note, please don't dig too much into this on my behalf--I'm
> > hoping someone else has run into this issue and figured it out.  Now that
> > I
> > know how to do it, I'm almost done with another DLL which does my keyboard
> > IO using the standard C libraries.  In other words, I'm replacing all my
> > "KeyPressed" and "ReadKey" calls with "CheckKey" and "GetKey" calls
> > respectively which, in turn, respectively call the C standard library
> > <conio.h> functions "_kbhit" and "getch".  But if there is a simple fix to
> > the KeyPressed issue, then my IO.pp unit can simply have an implementation
> > that calls KeyPressed and ReadKey instead of using the DLL.)
>
>First of all (as a general comment), you omitted one rather important
>information in your e-mail, and that is the target you compile for (plus
>some notes about the FPC version and the exact operating system version
>might help when discussing "strange" problems too - not everybody can link
>this to your previous e-mails in different thread). Anyway, I assume you
>talk about the Win32 target as in the other mails.

Yes, my apologies.  Windows XP development and target systems.  Both with
the latest SPs and patches.

FPC 2.0.0.

>  If this is the case,
>I'd guess that the problem might come from having two (incompatible)
>message handlers installed. This can e.g. happen when using unit Crt in
>parallel to e.g. unit Keyboard or Mouse with the current FPC version
>(known issues), or the second message handler might be directly in your
>"complex" program. If you don't need the Crt unit for anything else than
>KeyPressed and ReadKey functions, I'd suggest to use equivalent functions
>from unit Keyboard (PollKeyEvent and GetKeyEvent) and check whether this
>helps - the advantage of unit Keyboard to the C library is that it's
>multi-platform. If that doesn't help (which is certainly possible, of
>course - I don't know which units you use, so I'm just guessing here), it
>could be due to a conflict with message handler installed in the external
>C library you use (which I don't know either) and then using the C library
>functions might be your only choice.
>
>Hope this helps

Some, perhaps....I ran into this problem when I was still compiling the
program as a pure Pascal program.  (I had the interfaces to other languages
commented out.)

I'm using: CRT, IO, DOS, Video, Printer, Graph, and Drivers.  It's only one
or two modules that need Video, Printer, Graph and Drivers (not necessarily
the same ones).  But, of course when it all gets linked together, you only
need one reference to cause trouble, right?

And I don't care about multi-platform, so the C library DLL looks kind of
like the way to go.


Lowell C. Savage
[hidden email]
505-667-6964 (office/msg)
360-961-8965 (cell/msg)
505-667-4341 (shared fax)



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

Re: Re: KeyPressed

Michael Van Canneyt


On Mon, 22 Aug 2005, Lowell C. Savage wrote:

>
> Some, perhaps....I ran into this problem when I was still compiling the
> program as a pure Pascal program.  (I had the interfaces to other languages
> commented out.)
>
> I'm using: CRT, IO, DOS, Video, Printer, Graph, and Drivers.  

This is the problem. You can't use the Drivers, CRT and Video unit together.
Each of them tries to catch keystrokes, and they will randomly receive them.
(depending on thread usage).

You should use only Video or only CRT or only Drivers
(though it can be that drivers and video work together)

> It's only one or
> two modules that need Video, Printer, Graph and Drivers (not necessarily the
> same ones).  But, of course when it all gets linked together, you only need
> one reference to cause trouble, right?
>
> And I don't care about multi-platform, so the C library DLL looks kind of like
> the way to go.

It will still cause problems, because the C library also will interfere with the
Video and CRT units...

It's planned to base the CRT unit on the video unit (so they would work together),
but until now no-one had time.

Michael.

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

Re: Re: KeyPressed

Eduardo Morras
At 21:45 22/08/2005, you wrote:


>On Mon, 22 Aug 2005, Lowell C. Savage wrote:
>
> >
> > Some, perhaps....I ran into this problem when I was still compiling the
> > program as a pure Pascal program.  (I had the interfaces to other languages
> > commented out.)
> >
> > I'm using: CRT, IO, DOS, Video, Printer, Graph, and Drivers.
>
>This is the problem. You can't use the Drivers, CRT and Video unit together.
>Each of them tries to catch keystrokes, and they will randomly receive them.
>(depending on thread usage).
>
>You should use only Video or only CRT or only Drivers
>(though it can be that drivers and video work together)
>
> > It's only one or
> > two modules that need Video, Printer, Graph and Drivers (not
> necessarily the
> > same ones).  But, of course when it all gets linked together, you only need
> > one reference to cause trouble, right?
> >
> > And I don't care about multi-platform, so the C library DLL looks kind
> of like
> > the way to go.
>
>It will still cause problems, because the C library also will interfere
>with the
>Video and CRT units...
>
>It's planned to base the CRT unit on the video unit (so they would work
>together),
>but until now no-one had time.
>
>Michael.

I remember you can call any function/procedure/var/type/etc in a specific
unit using unitname:functionname  so call  Drivers:Keypressed or
CRT:Keypressed or Vide:Keypressed.

But perhaps i remember wrong.


------------------------------------------------------------
Alien.org contacted...    waiting for Ripley


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

Re: Re: KeyPressed

Marco van de Voort
> >On Mon, 22 Aug 2005, Lowell C. Savage wrote:
> > > the way to go.
> >
> >It will still cause problems, because the C library also will interfere
> >with the
> >Video and CRT units...
> >
> >It's planned to base the CRT unit on the video unit (so they would work
> >together),
> >but until now no-one had time.
> >
> >Michael.
>
> I remember you can call any function/procedure/var/type/etc in a specific
> unit using unitname:functionname  so call  Drivers:Keypressed or
> CRT:Keypressed or Vide:Keypressed.
>
> But perhaps i remember wrong.

crt.keypressed etc. However that doesn't change the picture that Michael paints,
since the units must still be USES'd, and thus the init code that hooks input/output
are run.

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

Re: KeyPressed

Lowell C. Savage
In reply to this post by Lowell C. Savage
Thanks for the replies Michael, Eduardo, and Martin!

It looks like I'll have to see what functions are being called to use the
Video and Drivers units and see what I can do to work around them or
something.  Ugh.  Oh well, better that than another dead end.

Thanks!

Lowell

Michael Van Canneyt <[hidden email]> wrote, in part:

> > I'm using: CRT, IO, DOS, Video, Printer, Graph, and Drivers.
>
>This is the problem. You can't use the Drivers, CRT and Video unit together.
>Each of them tries to catch keystrokes, and they will randomly receive them.
>(depending on thread usage).
>
>You should use only Video or only CRT or only Drivers
>(though it can be that drivers and video work together)
>
> > And I don't care about multi-platform, so the C library DLL looks kind
> of like
> > the way to go.
>
>It will still cause problems, because the C library also will interfere
>with the
>Video and CRT units...
>
>It's planned to base the CRT unit on the video unit (so they would work
>together),
>but until now no-one had time.
>
>From: [hidden email] (Marco van de Voort)
>
>crt.keypressed etc. However that doesn't change the picture that Michael
>paints,
>since the units must still be USES'd, and thus the init code that hooks
>input/output
>are run.

Lowell C. Savage
[hidden email]
505-667-6964 (office/msg)
360-961-8965 (cell/msg)
505-667-4341 (shared fax)



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

Re: Re: KeyPressed

Tomas Hajny
In reply to this post by Michael Van Canneyt
Date sent:       Mon, 22 Aug 2005 21:45:05 +0200 (CEST)
From:           Michael Van Canneyt <[hidden email]>
To:             FPC-Pascal users discussions <[hidden email]>
Subject:         Re: [fpc-pascal] Re:  KeyPressed
Send reply to:   FPC-Pascal users discussions <[hidden email]>
        <mailto:[hidden email]?subject=unsubscribe>
        <mailto:[hidden email]?subject=subscribe>


> > Some, perhaps....I ran into this problem when I was still compiling
> > the program as a pure Pascal program.  (I had the interfaces to
> > other languages commented out.)
> >
> > I'm using: CRT, IO, DOS, Video, Printer, Graph, and Drivers.  
>
> This is the problem. You can't use the Drivers, CRT and Video unit
> together. Each of them tries to catch keystrokes, and they will
> randomly receive them. (depending on thread usage).
>
> You should use only Video or only CRT or only Drivers
> (though it can be that drivers and video work together)
>
> > It's only one or
> > two modules that need Video, Printer, Graph and Drivers (not
> > necessarily the same ones).  But, of course when it all gets linked
> > together, you only need one reference to cause trouble, right?
> >
> > And I don't care about multi-platform, so the C library DLL looks
> > kind of like the way to go.
>
> It will still cause problems, because the C library also will
> interfere with the Video and CRT units...
>
> It's planned to base the CRT unit on the video unit (so they would
> work together), but until now no-one had time.

Yes - it's specifically Crt plus Drivers (which in turn uses Keyboard
and Mouse units), which interfere. Crt should be rewritten to use
unit Keyboard for ReadKey and KeyPressed implementation - this should
probably resolve most of the problems. The other part (Crt accessing
console independently of the Video unit) isn't good design, but
shouldn't be causing your problems.

Tomas

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

Re: KeyPressed

Lowell C. Savage
In reply to this post by Lowell C. Savage
Thanks!  That was it.  I had been working on removing the video unit.  I
put it back in and yanked the drivers unit.  Now it works.  (Although I'm
not sure if the program actually does use CGA graphics in another part of
the program--in case it does, I'd appreciate any ideas people would have.)

Thanks again, Tomas!

Lowell
Tomas Hajny wrote, in part:
>Yes - it's specifically Crt plus Drivers (which in turn uses Keyboard
>and Mouse units), which interfere. Crt should be rewritten to use
>unit Keyboard for ReadKey and KeyPressed implementation - this should
>probably resolve most of the problems. The other part (Crt accessing
>console independently of the Video unit) isn't good design, but
>shouldn't be causing your problems.

Lowell C. Savage
[hidden email]
505-667-6964 (office/msg)
360-961-8965 (cell/msg)
505-667-4341 (shared fax)



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