Touch Keyboard Guide
TTMSFNCTouchKeyboard is a visual virtual keyboard that posts keystrokes to whichever control has focus in the application. TTMSFNCPopupTouchKeyboard is a non-visual companion that shows the same keyboard in a floating popup, making it easy to show the keyboard only when an input control is focused.
Both controls work on Windows, macOS, and TMS WEB Core. Custom keyboard layouts can be saved and loaded on desktop platforms.
Available keyboard types
| Type | Description |
|---|---|
ktQWERTY |
Standard QWERTY layout |
ktAZERTY |
French AZERTY layout |
ktQWERTZ |
Central European QWERTZ layout |
ktDVORAK |
Dvorak layout |
ktNUMERIC |
Numeric keypad |
ktCELLPHONE |
Mobile-style phone keypad |
ktCustom |
Custom layout (Windows only) |
Using TTMSFNCTouchKeyboard
Drop the control on the form and configure the layout type. With AutoPostKey := True the keyboard sends keystrokes to the OS without needing to wire it to a specific edit control.
// Drop TTMSFNCTouchKeyboard on the form and configure the keyboard type
TMSFNCTouchKeyboard1.KeyboardType := ktQWERTY;
TMSFNCTouchKeyboard1.AutoPostKey := True; // automatically posts keystrokes to the focused control
TMSFNCTouchKeyboard1.AutoCapsDisplay := True; // shows uppercase labels when caps lock is active
TMSFNCTouchKeyboard1.BorderRounding := 5;
TMSFNCTouchKeyboard1.KeySpacing := 3;
TMSFNCTouchKeyboard1.AllowAutoZoom := True;
// The keyboard sends keystrokes to whichever window control has focus.
// No wiring to a specific edit control is needed when AutoPostKey is True.
Using TTMSFNCPopupTouchKeyboard
TTMSFNCPopupTouchKeyboard is non-visual. Call ShowKeyboard when an input control gains focus and HideKeyboard when it loses focus.
// TTMSFNCPopupTouchKeyboard is a non-visual component.
// Call ShowKeyboard to display the keyboard in a floating popup,
// HideKeyboard to dismiss it.
procedure TForm1.EditFocusEnter(Sender: TObject);
begin
TMSFNCPopupTouchKeyboard1.KeyboardType := ktQWERTY;
TMSFNCPopupTouchKeyboard1.ShowKeyboard;
end;
procedure TForm1.EditFocusExit(Sender: TObject);
begin
TMSFNCPopupTouchKeyboard1.HideKeyboard;
end;
Saving and loading layouts and handling key clicks
The SaveKeybdLayout and LoadKeybdLayout methods persist the full key layout — positions, captions, key values, and special keys — to and from a file. OnKeyClick fires after each key press and provides the key index.
// Save and load a custom keyboard layout (desktop platforms)
procedure TForm1.ButtonSaveLayoutClick(Sender: TObject);
begin
TMSFNCTouchKeyboard1.SaveKeybdLayout('custom.kbd');
end;
procedure TForm1.ButtonLoadLayoutClick(Sender: TObject);
begin
TMSFNCTouchKeyboard1.LoadKeybdLayout('custom.kbd');
end;
// OnKeyClick fires after a key is pressed; use it to log or intercept keystrokes
procedure TForm1.TMSFNCTouchKeyboard1KeyClick(Sender: TObject; AIndex: Integer);
begin
Memo1.Lines.Add('Key index pressed: ' + IntToStr(AIndex));
end;
Combining popup mode, layout persistence, and key-click handling
The following example shows a popup keyboard that activates when an edit gains focus, persists a custom layout between sessions, and logs each keystroke via OnKeyClick:
procedure TForm1.Edit1Enter(Sender: TObject);
begin
TMSFNCPopupTouchKeyboard1.ShowKeyboard(Edit1);
end;
procedure TForm1.Edit1Exit(Sender: TObject);
begin
TMSFNCPopupTouchKeyboard1.HideKeyboard;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
// restore custom layout saved from a previous session
if FileExists('layout.kb') then
TMSFNCPopupTouchKeyboard1.LoadKeybdLayout('layout.kb');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
TMSFNCPopupTouchKeyboard1.SaveKeybdLayout('layout.kb');
end;
procedure TForm1.TMSFNCPopupTouchKeyboard1KeyClick(
Sender: TObject; AKeyIndex: Integer);
begin
StatusBar1.SimpleText := 'Key ' + IntToStr(AKeyIndex) + ' pressed';
end;