[Lazarus] intercepting keyboard events
Ondrej Pokorny
lazarus at kluug.net
Mon May 22 16:01:04 CEST 2017
On 22.05.2017 15:57, Graeme Geldenhuys via Lazarus wrote:
> On 2017-05-08 17:46, zeljko via Lazarus wrote:
>> Just to be sure that control actually can take focus put this
>> ControlStyle := ControlStyle - [csNoFocus];
>> into constructor of your control.
>
> And what if that doesn't work? I've set that in the constructor, but
> still it doesn't receive keyboard focus (after I've clicked on the
> custom control)?
>
> What else can I try?
>
> eg:
> I have a PageControl which contains my custom control. I then have a
> treeview on the right. If the treeview had focus, and I click on my
> custom control and then press some keys (eg: Up/Down) then the focused
> node in the treeview changes. Keyboard focus doesn't seem to want to
> move to the custom control.
>
> ps #2:
> Interacting with a mouse on my custom control seems to work (but
> then I have SetFocus in the MouseDown too).
Zeljko was wrong in his statement. The csNoFocus is just a helper flag
that custom controls should follow but don't have to. TWinControl
directly doesn't do anything. with csNoFocus - it doesn't have any
meaning for it.
Follow my instruction from my previous email in this thread:
If you mean receiving focus by clicking on it then yes, you need to call
SetFocus in MouseDown. It's also a good idea to check the csNoFocus flag
(from ControlStyle property).
For an example look how it is done in TCustomDBGrid.MouseDown.
+ The control can always get focused by the Tab key, if TabStop=True.
Ondrej
More information about the Lazarus
mailing list