Board index » delphi » Global KeyDown handler ??

Global KeyDown handler ??

How can I make a KeyDown handler wich is not tied to
a particular Window/Control but applies anywhere in
my program. If I make a KeyDown event for the
main Form (I only have 1 in this case) it works if no
component on the Form is Focused but not otherwise.
Help
Thanks !
JPI
 

Re:Global KeyDown handler ??


Set your form's KeyPreview property to TRUE

Quote
JPI wrote:

> How can I make a KeyDown handler wich is not tied to
> a particular Window/Control but applies anywhere in
> my program. If I make a KeyDown event for the
> main Form (I only have 1 in this case) it works if no
> component on the Form is Focused but not otherwise.
> Help
> Thanks !
> JPI

--
--------------------------------------
Pirch resources
--
http://pirchworld.com
--------------------------------------

Re:Global KeyDown handler ??


How come I never noticed that property ?
Thanks !

Re:Global KeyDown handler ??


I think that if you set the 'keypreview' property of your form to true then
it will read keys no matter what control is selected.

Nick.

JPI <j...@pp.netsor.fi> wrote in article
<0HeA7.92$wn2.6...@read2.inet.fi>...

Quote
> How can I make a KeyDown handler wich is not tied to
> a particular Window/Control but applies anywhere in
> my program. If I make a KeyDown event for the
> main Form (I only have 1 in this case) it works if no
> component on the Form is Focused but not otherwise.
> Help
> Thanks !
> JPI

Re:Global KeyDown handler ??


For a single form you can use the KeyPreview property.
If you have multiple forms you'll have to use the OnMessage event of the
Application object to trap keypresses.

Quote
"JPI" <j...@pp.netsor.fi> wrote in message

news:0HeA7.92$wn2.6105@read2.inet.fi...
Quote
> How can I make a KeyDown handler wich is not tied to
> a particular Window/Control but applies anywhere in
> my program. If I make a KeyDown event for the
> main Form (I only have 1 in this case) it works if no
> component on the Form is Focused but not otherwise.
> Help
> Thanks !
> JPI

Other Threads