Hacking the TTouchKeyboard Part I
Hacking the TTouchKeyboard Part II
Hacking the TTouchKeyboard Part III
Hacking the TTouchKeyboard Part IV
Hacking the TTouchKeyboard Part V (not published yet)
The TTouchKeyboard is a a fairly flexible on screen keyboard that supports multiple keyboard layouts but only shipped with the number pad and the standard keyboard layout for a whole lot of input languages. How to create these keyboard layouts has been a mystery, until now. Over the next few posts I'll provide some tools, documentation and sample code to build everything you need to hack the TTouchKeyboard.
The first bit of code I'm going to provide demonstrates listing all the keyboard layouts that are available. It's pretty simple really. A keyboard layout is just a resource with the string "KEYBOARD" in the name.
procedure GetKeyboardLayoutNames(ANames: TStrings); function EnumResNames(Module: HMODULE; ResType, ResName: PChar; Nothing: Pointer): Integer; stdcall; const sResourceName = 'KEYBOARD'; begin if Pos(sResourceName, ResName) > 0 then LayoutNames.Add(ResName); Result := 1; end; begin LayoutNames := TStringList.Create; try EnumResourceNames(HInstance, RT_RCDATA, @EnumResNames, 0); ANames.Clear; ANames.AddStrings(LayoutNames); finally FreeAndNil(LayoutNames); end; end;
Once you have a layout you can load it by calling this little function.
function LoadLayout(const LayoutName: string): TVirtualKeyLayout; var Stream: TResourceStream; TempStream: TStream; begin Result := nil; Stream := TResourceStream.Create(HInstance, LayoutName, RT_RCDATA); try Result := TVirtualKeyLayout.Create; Result.LoadFromStream(Stream); finally Stream.Free; end; end;
Next I'll show how to iterate the data structures and save it to an XML file for easy text manipulation.