unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
redt1: TRichEdit;
procedure redt1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
IsSpecialString:Boolean;
SpecialString :string;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
IsSpecialString :=False;
SpecialString :='';
end;
function GetCharFromVirtualKey(Key: Word): string;
var//http://delphi.about.com/od/adptips2006/qt/vkey2char.htm
keyboardState: TKeyboardState;
asciiResult: Integer;
begin
GetKeyboardState(keyboardState) ;
SetLength(Result, 2) ;
asciiResult := ToAscii(key, MapVirtualKey(key, 0), keyboardState, @Result[1], 0) ;
case asciiResult of
0: Result := '';
1: SetLength(Result, 1) ;
2:;
else
Result := '';
end;
end;
procedure TForm1.redt1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if not IsSpecialString then
begin
SpecialString :='';
if GetCharFromVirtualKey(Key)='/' then
begin
IsSpecialString :=True;
SpecialString :=GetCharFromVirtualKey(Key);
end;
end
else begin
if Key=VK_BACK then
SpecialString :=Copy(SpecialString,1,Length(SpecialString)-1)
else
SpecialString :=SpecialString +GetCharFromVirtualKey(Key);
if SpecialString='/Test' then
begin
IsSpecialString :=False;
redt1.SelLength :=0;
redt1.SelStart :=redt1.SelStart -Length(SpecialString) +1;
redt1.SelLength :=Length(SpecialString);
redt1.SelText :='Test is Ok http://www.yesky.com/TLimages/smile/face01.gif';
SpecialString :='';
end;
end;
Caption :=SpecialString;
end;
end.