[Lazarus] RE : LCL and custom keyboard layouts

Sven Barth pascaldragon at googlemail.com
Sat Jan 28 18:48:34 CET 2012


On 28.01.2012 18:38, Mark Morgan Lloyd wrote:
> Ludo Brands wrote:
>>> I'll start digging in and see where I get to, but any suggestions-
>>> particularly relating to Linux- will be welcome.
>>>
>>
>> Under X11 you can modify your keyboard to your likings. 4 levels per
>> key are
>> standard using Shift and 3 lvl key (Altgr on most non-Eglish kbd but
>> configurable to any key). Keys can be defined with their unicode code
>> (Uxxxx
>> format).
>> A nice howto here:
>> http://people.uleth.ca/~daniel.odonnell/Blog/custom-keyboard-in-linuxx11
>> .
>> As usual, locations of the kbd files differ from distribution to
>> distribution and even between versions.
>
> Thanks Ludo. I'm already doing a bit of custom stuff to get A+ running
> (arguably the largest free APL that still uses the original characters).
> But the question remains: once inside a Lazarus app, can I hook keycodes
> using a custom procedure, translate them to Unicode, and inject them
> into the currently-focussed edit-capable control?
>

Take a look at the OnKeyDown and OnKeyUp events. Their "Key" argument is 
a "var" one. You can "cancel" the default routine of the control the 
handler is assigned to by setting the "Key" to "0" after you processed it.

E.g.

procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: 
TShiftState
   );
begin
   Key := 0;
   Edit1.SelText := #$e2#$9b#$a4;
end;

This will insert a "pentagramm" at the current cursor position of 
"Edit1" (you'll only see it if you have a font that contains that 
character).

You will then need to implement things like "key is hold down thus 
insert character until released" yourself using a timer and OnKeyUp.

Also you can assign one event handler to multiple TEdits (or other 
controls that support OnKeyDown/-Up) so you have only one routine which 
uses the "Sender" parameter to differentiate the action to do.

PS: Maybe this is not the best solution (I never needed to do something 
like this), but it should work.

Regards,
Sven




More information about the Lazarus mailing list