[Lazarus] LCL and custom keyboard layouts

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Tue Jan 31 10:17:52 CET 2012


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.

-- 
Felipe Monteiro de Carvalho




More information about the Lazarus mailing list