Board index » delphi » Keyboard input ; Delphi 4 help

Keyboard input ; Delphi 4 help

Does anyone know how, in Delphi 4, to either
(a) get keyboard input on things like panels;
(b) have a default so that ANY part of a form, which does not have a
specific keyboard input, can have a default key press/down et cetera?

I am finding Delphi 4 satisfyingly bug-fixed after Delphi 2, but find that
its HELP is not nearly so useful unless you already know everything you are
searching for help on.  The essays in Delphi 2 gave you the option to scan
to find out what property or method you wanted to use.  Losing this has been
a big blow!  Any comments?

Chester Wilson
ches...@tpgi.com.au

 

Re:Keyboard input ; Delphi 4 help


Quote
> Does anyone know how, in Delphi 4, to either
> (a) get keyboard input on things like panels;
> (b) have a default so that ANY part of a form, which does not have a
> specific keyboard input, can have a default key press/down et cetera?

Chester,

in Windows keyboard input is associated with the concept of focus: to receive
keyboard messages a window has to aquire the focus by calling the SetFocus API
function (TwinControl et Cie. have a method of the same name that calls the
API method). If no window has the focus in an application then no keyboard
messages are generated for the application.

It is easy enough to teach a TPanel to take the focus: just call its SetFocus
method on a mouse down event. TPanel inherits all the OnKey events from
TWinControl, they are just not published. That can be fixed in an appropriate
descendent.

Your b) is more difficult. The form itself can also take the focus if you call
its Setfocus method but usually some control on the form will have the focus
(unless you have no control that can take it on the form). In this case
setting the forms KeyPreview to True enables you to "echo" the key events the
control with focus sees to the forms OnKey event handlers.

You can also trap key combinations by making them hotkeys for menu items. That
would even work when no control has the focus, but of course it requires a
main menu in the first place.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitely requested!

Other Threads