[Lazarus] LCL and custom keyboard layouts
Mark Morgan Lloyd
markMLl.lazarus at telemetry.co.uk
Wed Feb 22 13:22:57 CET 2012
Felipe Monteiro de Carvalho wrote:
> On Mon, Jan 30, 2012 at 11:55 AM, Mark Morgan Lloyd
> <markMLl.lazarus at telemetry.co.uk> wrote:
>> Thanks for that Felipe. So if I'm reading you correctly, as a crude hack I
>> should be able to start by hooking OnKeyDown etc. as exposed by (instances
>> of) descendants of TWinControl. But there's probably more ethical ways to do
>> it based on at least partial replacement of elements of the LCL.
>
> Maybe I am missunderstand here, but you want to send keyboard events
> from the hardware to the LCL application correct? If yes, then No, you
> dont want to hook to OnKeyDown. OnKeyDown is what the control handles
> (actually usually the KeyDown virtual method), but is not the first
> step in the event chain.
>
> If you want to simulate a keyboard you have to send LM_KEYDOWN /
> LM_KEYUP and UTF8Char messages to controls. Convenience routines for
> sending those messages are located in the unit lcl/LCLMessageGlue.pas
> in these routines:
>
> function LCLSendKeyDownEvent(const Target: TControl; var CharCode:
> Word; KeyData: PtrInt; BeforeEvent, IsSysKey: Boolean): PtrInt;
> function LCLSendKeyUpEvent(const Target: TControl; var CharCode: Word;
> KeyData: PtrInt; BeforeEvent, IsSysKey: Boolean): PtrInt;
> function LCLSendCharEvent(const Target: TControl; var CharCode: Word;
> KeyData: PtrInt; BeforeEvent, IsSysKey, ANotifyUserInput: Boolean):
> PtrInt;
> function LCLSendUTF8KeyPress(const Target: TWinControl; AUTF8Char:
> TUTF8Char; IsSysKey: Boolean): PtrInt;
>
> So these are the routines you want to use for a LCL-only solution.
>
> For a system wide solution you would need to figure out how to get
> your keyboard messages to X11.
As a summary, at the level of an individual control (specifically,
synedit) hooking OnKeyDown and OnKeyUp and using those to toggle a flag
for the AltGr key (which my system at least lumps in with Alt as far as
the shift parameter is concerned) allows me to see the non-standard key
combinations. A lookup table converts to the applicable UTF-8
characters, which I can then inject using the target control's
IntfUTF8KeyPress(), noted your suggestion of LCLSendUTF8KeyPress() but
that's only available in trunk.
I've not yet investigated the behaviour of Solaris, which has a compose
key for dieresis etc.
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
More information about the Lazarus
mailing list