Board index » delphi » Keyboard input

Keyboard input

I have a need to scan for keyboard activity, similar to using kbhit()
from C++.

I am processing in a while loop and would like to have the loop break if
a key is pressed.  Using the KeyDown or FormKeyDown do not have any
affect while I am in this loop.

It seems like it should be simple but I am missing something.  Does
anyone have any ideas??

Thanks for any help

Rod Leach

--

 

Re:Keyboard input


In article <37346D11.C22D9...@netins.net>, rle...@netins.net says...

Quote

>I have a need to scan for keyboard activity, similar to using kbhit()
>from C++.

>I am processing in a while loop and would like to have the loop break if
>a key is pressed.  Using the KeyDown or FormKeyDown do not have any
>affect while I am in this loop.

>It seems like it should be simple but I am missing something.  Does
>anyone have any ideas??

You have to include Application.ProcessMessages in your loop to ensure that the
VCL can react to windows messages (eg. a keypress). Example:

some loop in program:

  stop := false;
  while not stop do
  begin
    // loop code
    Application.ProcessMessages
  end;

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
  stop := true;
end;

Remember to set the Form's KeyPreview property to true.

--
Christo Crause
Thermal Separations Research
University of Stellenbosch
South Africa

Re:Keyboard input


Why don't you use a thread for the process & use the event OnKeyDown
& FormKeyDown to stop it ?

(Sorry for my bad English but i'm an Italian boy)

by Albe on aa...@lycosmail.com

Quote
Rod Leach <rle...@netins.net> wrote in message

37346D11.C22D9...@netins.net...
Quote
> I have a need to scan for keyboard activity, similar to using kbhit()
> from C++.

> I am processing in a while loop and would like to have the loop break if
> a key is pressed.  Using the KeyDown or FormKeyDown do not have any
> affect while I am in this loop.

> It seems like it should be simple but I am missing something.  Does
> anyone have any ideas??

> Thanks for any help

> Rod Leach

> --

Other Threads