unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
c: char;
LowCh: boolean;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var
ch: word;
begin
if (Ord(Key) and $80) <> 0 then
begin
if not LowCh then
begin
LowCh := True;
c := Key;
end else
begin
ch := (((Ord(c) shl 8) or ord(Key)) and $7f7f) xor $2020;
LowCh := False;
if (ch = $030C) or (ch > $1000) then // $030c中文逗号,$1000纯汉字
begin
Edit1.Text := Edit1.Text + c + key;
PostMessage(Edit1.Handle, WM_KEYDOWN, VK_END, 0);
end;
end;
end;
if Key >= #32 then
Key := #0;
end;
end.