Touch-It Virtual Keyboard Version 4.9.2
Automation

This topic demonstrates how to drive Touch-It using automation.

Connecting to the automation server

If Touch-It is not running when this function is called, it will be started automatically and closed when your application ends.
Interface

var

//Server object
TIServer :variant;


implementation

uses
ComObj;

procedure TForm1.FormCreate(Sender :TObject);
begin

TIServer := CreateOleObject('TouchIt.Automation');

end;

Disconnecting from the server

Simply:
procedure TForm1.FormClose(Sender :TObject);
begin

TIServer.Hide;
TIServer := UnAssigned;

end;

Minimize and restore all keyboards

Delphi example of how to show and hide keyboards.

procedure Show;
procedure Hide;
procedure Button1Click(Sender :TObject);
begin

//Restore
TIServer.Show;

end;

procedure Button2Click(Sender :TObject);
begin

//Minimize
TIServer.Hide;

end;

Open a keyboard

Delphi example of how to open a keyboard. It's position is based on the setup. See also OpenAs below.

procedure Open (aFileName: OleVariant; aMonitor: Integer);
  • aFileName
    • Template file name or identification. (ID)
  • aMonitor
    • Select on which monitor to display the keyboard.
      • 0: 1st monitor
      • 1: 2nd
      • etc.
procedure Button1Click(Sender :TObject);
begin

//Open the templatekb_compact001.kbl using the file name on 1st monitor
TIServer.Open('kb_compact001.kbl', 0);

end;

procedure Button2Click(Sender :TObject);
begin

//Open the template kb_medium002.kbl using its ID on 2nd monitor
TIServer.Open(2, 1);

end;

Close a keyboard

Delphi example of how to close a keyboard.

procedure Close (aFileName: OleVariant; aMonitor: Integer);
  • aFileName
    • Template file name or identification. (ID)
  • aMonitor
    • Select on which monitor to display the keyboard.
      • -1: On any monitor
      • 0: 1st monitor
      • 1: 2nd
      • etc.
procedure Button3Click(Sender :TObject);
begin

//Close the template kb_compact001.kbl using the file name on any monitor
TIServer.Close('kb_compact001.kbl', -1);

end;

procedure Button4Click(Sender :TObject);
begin

//Close the template kb_medium002.kbl using its ID on 1st monitor
TIServer.Close(2, 0);

end;

Taskbar or floating keyboard (Open a keyboard)

Delphi example of how to either select a taskbar or a floating keyboard using the OpenAs method. If the keyboard is not yet visible, OpenAs opens it before setting its position.

procedure OpenAs (aFileName: OleVariant; aPos, aMonitor: Integer);
  • aFileName
    • Template file name or identification. (ID)
  • aPos
    • -1: Default position defined in the setup.
    • 0: Left appbar
    • 1: Top appbar
    • 2: Right appbar
    • 3: Bottom appbar
    • 4: Floating
    • 5: Reserved
    • 6: Reserved
    • 7: Top-left corner
    • 8: Top-right corner
    • 9: Bottom-left corner
    • 10: Bottom-right corner
  • aMonitor
    • Select on which monitor to display the keyboard.
      • 0: 1st monitor
      • 1: 2nd
      • etc.
procedure Button1Click(Sender :TObject);
begin

//Open the templatekb_compact001.kbl using the file name, as a floating keyboard on 2nd monitor
TIServer.OpenAs('kb_compact001.kbl', 4, 1);

end;

procedure Button2Click(Sender :TObject);
begin

//Open the template kb_medium002.kbl using its ID, as a bottom appbar on the 1st monitor
TIServer.OpenAs(2, 3, 0);

end;

Reload keyboards templates

In some circonstances, like modifying the touchit.ini file, it is necessary to restart keyboards for the modifications to take effect.

procedure Reload;
procedure SpinEditChange(Sender :TObject);
begin

TIServer.Reload;

end;
In some circumstances, the docked templates may become invisible. In this case it is better to close and reopen Touch-It as follow:
procedure Button2Click(Sender :TObject);
begin

SendMessage(FindWindow(nil, PChar('Touch-It Keyboard'), WM_CLOSE, 0, 0);
ShellExecute(0, 'open', 'touchit.exe', nil, nil, SW_SHOW);

end;

Floating keyboard position

Delphi example of how to set the keyboard on screen position.

1. SetPos

sets absolute keyboard position.

procedure SetPos (aLeft, aTop: integer);
procedure SpinEditChange(Sender :TObject);
begin

TIServer.SetPos(SpinEdit1.Value, SpinEdit2.Value);

end;

2. SetBoundsPos

sets keyboard position above or beneath an edit control without hidding it.

procedure SetBoundsPos (aLeft, aTop, aRight, aBottom: integer);
procedure Button2Click(Sender :TObject);
begin

//ClientToScreen retreives screen coordinates of the control
with TControl(Sender), ClientToScreen(Point(0, 0)) do

TIServer.SetBoundsPos(x, y, x +Width, y +Height);

end;

Optimize painting process (Layered only)

Painting can be rather long when the Windows style is set to Layered (See Setup\Advance). To optimize the process when a few lights states or texts must change, Touch-It implements procedures to lock the keyboards update and to flush all modification at once.

A Lock counter is used. Updating is performed only when the couter equals 0. Thus it is possible to have recursive call to the Lock/Unlock procedures.

procedure Lock;
Keep the keyboard from updating, increase the lock counter.

procedure Unlock;
Decrease the counter and update if the counter equals 0.

procedure ResetLock;
In case of exceptions in your application, call ResetLock from your exception handler to clear the lock counter and update if needed. You don't need to call Lock/Unlock if you use LightOne or LightRange as they already implement these calls.
Copyright © 2011 Chessware SA