先做个HOOK,勾到了你定义的键就调用下面函数 sSend 就是那句话 procedure TOpThread.SendKeys(sSend:string); var i:integer; focushld,windowhld:hwnd; threadld:dword; ch: byte; begin windowhld:=GetForegroundWindow; threadld:=GetWindowThreadProcessId(Windowhld,nil); AttachThreadInput(GetCurrentThreadId,threadld,true); Focushld:=getfocus; AttachThreadInput(GetCurrentThreadId,threadld,false); if focushld = 0 then Exit; i := 1; while i <= Length(sSend) do begin ch := byte(sSend[i]); if Windows.IsDBCSLeadByte(ch) then begin Inc(i); SendMessage(focushld, WM_IME_CHAR, MakeWord(byte(sSend[i]), ch), 0); end else SendMessage(focushld, WM_IME_CHAR, word(ch), 0); Inc(i); end; end;
sSend 就是那句话
procedure TOpThread.SendKeys(sSend:string);
var
i:integer;
focushld,windowhld:hwnd;
threadld:dword;
ch: byte;
begin
windowhld:=GetForegroundWindow;
threadld:=GetWindowThreadProcessId(Windowhld,nil);
AttachThreadInput(GetCurrentThreadId,threadld,true);
Focushld:=getfocus;
AttachThreadInput(GetCurrentThreadId,threadld,false);
if focushld = 0 then Exit;
i := 1;
while i <= Length(sSend) do
begin
ch := byte(sSend[i]);
if Windows.IsDBCSLeadByte(ch) then
begin
Inc(i);
SendMessage(focushld, WM_IME_CHAR, MakeWord(byte(sSend[i]), ch), 0);
end
else
SendMessage(focushld, WM_IME_CHAR, word(ch), 0);
Inc(i);
end;
end;