var
MyHwnd:HWND;
KeyValue:integer;
begin
{功能模拟发送按键:1~9,F1~F8}
MyHwnd:=FindWindow(nil,'Element Client');
if Str='1' then KeyValue:=49;
if Str='2' then KeyValue:=50;
if Str='3' then KeyValue:=51;
if Str='4' then KeyValue:=52;
if Str='5' then KeyValue:=53;
if Str='6' then KeyValue:=54;
if Str='7' then KeyValue:=55;
if Str='8' then KeyValue:=56;
if Str='9' then KeyValue:=57;
if Str='F1' then KeyValue:=VK_F1;
if Str='F2' then KeyValue:=VK_F2;
if Str='F3' then KeyValue:=VK_F3;
if Str='F4' then KeyValue:=VK_F4;
if Str='F5' then KeyValue:=VK_F5;
if Str='F6' then KeyValue:=VK_F6;
if Str='F7' then KeyValue:=VK_F7;
if Str='F8' then KeyValue:=VK_F8;
sendmessage(MyHwnd,wm_keydown,KeyValue,0);
sendmessage(MyHwnd,wm_keyup,KeyValue,0);
end;
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
if StrToFloat(Edit1.text) < 1 then Edit1.Text:='1'; //Timer能接受最小的值为1
if CheckBox1.Checked then
begin
Timer1.Enabled:=True;
Timer1.Interval:=Round(StrToFloat(Edit1.text)*1000); //1秒=1000毫秒 Round对一个实数进行四舍五入
Edit1.Enabled:=False;
end
else
begin
Timer1.Enabled:=False;
Edit1.Enabled:=True;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Timer1.Enabled:=false;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
SendKey(ComboBox1.text);//ComboBox1.text
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9','.',#8]) then key:=#0; //数字删除键
if (key='.') and (Pos('.',Edit1.Text)>0) then key:=#0;//只能数字且只能输入
end;
//按键模拟 1 2 3 4 5 6
procedure SendKey(Str:string);
var
MyHwnd:HWND;
KeyValue:integer;
begin
{功能模拟发送按键:1~9,F1~F8}
MyHwnd:=FindWindow(nil,'Element Client');
if Str='1' then KeyValue:=49;
if Str='2' then KeyValue:=50;
if Str='3' then KeyValue:=51;
if Str='4' then KeyValue:=52;
if Str='5' then KeyValue:=53;
if Str='6' then KeyValue:=54;
if Str='7' then KeyValue:=55;
if Str='8' then KeyValue:=56;
if Str='9' then KeyValue:=57;
if Str='F1' then KeyValue:=VK_F1;
if Str='F2' then KeyValue:=VK_F2;
if Str='F3' then KeyValue:=VK_F3;
if Str='F4' then KeyValue:=VK_F4;
if Str='F5' then KeyValue:=VK_F5;
if Str='F6' then KeyValue:=VK_F6;
if Str='F7' then KeyValue:=VK_F7;
if Str='F8' then KeyValue:=VK_F8;
sendmessage(MyHwnd,wm_keydown,KeyValue,0);
sendmessage(MyHwnd,wm_keyup,KeyValue,0);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SendKey('F1');//ComboBox1.text
end;