procedure SendText(ds:string);
var
TI: TInput;
KI: TKeybdInput;
i: integer;
begin
TI.Itype := INPUT_KEYBOARD;
for i := 1 to Length(ds) do
begin
KI.wVk := Ord(UpCase(ds[i]));
KI.dwFlags := 0;
TI.ki := KI;
SendInput(1, TI, SizeOf(TI));
KI.dwFlags := KEYEVENTF_KEYUP;
TI.ki := KI;
SendInput(1, TI, SizeOf(TI));
end;
end;
如何添加Unicode?有关如何使用SendInput(Edit1.Text);
答案 0 :(得分:7)
在此示例中,我使用了JclUnicode.pas中的单位JEDI project。如果你有Delphi 6,那么你可以省略uses子句中的JclUnicode。
uses
JclUnicode;
procedure SendText(const Value: WideString);
var
I: Integer;
S: WideString;
TI: TInput;
KI: TKeybdInput;
const
KEYEVENTF_UNICODE = $0004;
begin
S := WideUpperCase(Value);
TI.Itype := INPUT_KEYBOARD;
for I := 1 to Length(S) do
begin
KI.wVk := 0;
KI.dwFlags := KEYEVENTF_UNICODE;
KI.wScan := Ord(S[I]);
TI.ki := KI;
SendInput(1, TI, SizeOf(TI));
end;
end;
答案 1 :(得分:0)
uses
JclUnicode;
procedure SendText(const Value: WideString);
var
I: Integer;
S: WideString;
TI: TInput;
KI: TKeybdInput;
const
KEYEVENTF_UNICODE = $0004;
begin
S := WideUpperCase(Value);
TI.Itype := INPUT_KEYBOARD;
for I := 1 to Length(S) do
begin
KI.wVk := 0;
KI.dwFlags := KEYEVENTF_UNICODE;
KI.wScan := Ord(S[I]);
TI.ki := KI;
SendInput(1, TI, SizeOf(TI));
// release keys to avoid double key missing (like P in UPPER)
KI.dwFlags := KEYEVENTF_KEYUP;
TI.ki := KI;
SendInput(1, @TI, SizeOf(TI));
end;
end;