delphi编写能够模拟键盘输入应用程序的源代码

来源:百度知道 编辑:UC知道 时间:2024/06/20 03:48:32

下面是我很多年前编写的一个在“江湖”游戏里面泡点的程序,该程序手动选择浏览器的HANDLE,然后自动完成打怪、发言等功能。,程序如下:

program jianghu;

{$apptype console}

uses windows,messages;

function GetFocusHld: hwnd;
var
windowhld:hwnd;
threadld:dword;
begin
windowhld:=GetForegroundWindow;
threadld:=GetWindowThreadProcessId(Windowhld,nil);
AttachThreadInput(GetCurrentThreadId,threadld,true);
Result:=getfocus;
AttachThreadInput(GetCurrentThreadId,threadld,false);
end;

procedure SendKeys(focushld:hwnd;sSend:string);
var
i:integer;
ch: byte;
begin
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_C