
PHP Code:
unit SensorKeyBoardWindows;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Forms, FMX.Dialogs, FMX.Edit,
FMX.StdCtrls, ShellApi, Winapi.Windows, Winapi.messages;
type
TSensorKeyBoardWindows = class
private
class function ExpandEnvironmentVar(var Value: string): Boolean;
protected
public
class procedure onEnterEdit(Sender: TObject);
class procedure onExitEdit(Sender: TObject);
end;
procedure KeyBoardInitialization(AForm: TObject);
implementation
// Инициализация сенсорной клавиатуры для всех эдитов на форме
procedure KeyBoardInitialization(AForm: TObject);
var
k: Integer;
begin
if AForm is TForm then
begin
for k := 0 to TForm(AForm).ComponentCount - 1 do
if TForm(AForm).Components[k] is TEdit then
begin
TEdit(TForm(AForm).Components[k]).OnEnter := TSensorKeyBoardWindows.onEnterEdit;
TEdit(TForm(AForm).Components[k]).OnExit := TSensorKeyBoardWindows.onExitEdit;
end;
end
else
raise Exception.Create('Передан не верный параметр: ' + AForm.ClassName);
end;
{ TSensorKeyBoardWindows }
class function TSensorKeyBoardWindows.ExpandEnvironmentVar(var Value: string): Boolean;
var
R: Integer;
Expanded: string;
procedure StrResetLength(var S: string);
var
I: Integer;
begin
for I := 0 to Length(S) - 1 do
if S[I + 1] = #0 then
begin
SetLength(S, I);
Exit;
end;
end;
begin
SetLength(Expanded, 1);
R := ExpandEnvironmentStrings(PChar(Value), PChar(Expanded), 0);
SetLength(Expanded, R);
Result := ExpandEnvironmentStrings(PChar(Value), PChar(Expanded), R) <> 0;
if Result then
begin
StrResetLength(Expanded);
Value := Expanded;
end;
end;
class procedure TSensorKeyBoardWindows.onEnterEdit(Sender: TObject);
var
S: string;
begin
S := '%CommonProgramW6432%\microsoft shared\ink\tabtip.exe';
ExpandEnvironmentVar(S);
ShellExecute(0, PChar('open'), PChar(S), nil, nil, SW_SHOWNORMAL);
end;
class procedure TSensorKeyBoardWindows.onExitEdit(Sender: TObject);
var
KeyBoardHandle: THandle;
begin
KeyBoardHandle := FindWindow('IPTip_Main_Window', nil);
if KeyBoardHandle <> 0 then
PostMessage(KeyBoardHandle, WM_SYSCOMMAND, SC_CLOSE, 0);
end;
end.