Delphi 实现 定时模拟键盘按键
这一部分函数我看不懂给思路也没用所以,直接给我源码实现点击button1后,每隔10秒钟自动按键H再点击button1,停止thanks...
这一部分函数我看不懂给思路也没用所以,直接给我源码实现点击button1后,每隔10秒钟自动按键H再点击button1,停止thanks
展开
1个回答
展开全部
给个完整源码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Button1: TButton;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const
VK_H=72;
var
Form1: TForm1;
tmn: Integer;
implementation
{$R *.dfm}
procedure VKClick(vk: Integer);
begin
KeyBD_Event(vk, MapVirtualKey(vk, 0), 0, 0);
Sleep(10);
KeyBD_Event(vk, MapVirtualKey(vk, 0), KeyEventF_KeyUp, 0);
Sleep(10);
end;
procedure TForm1.Button1Click(Sender: TObject);
const
star = '开始';
stop = '结束';
var
bnm: String;
begin
tmn := 0;
bnm := Button1.Caption;
if bnm = star then begin
Edit1.Text := '';
Timer1.Enabled := True;
bnm := stop;
end else begin
Timer1.Enabled := False;
bnm := star;
end;
Button1.Caption := bnm;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Inc(tmn);
Label1.Caption := IntToStr(tmn);
if tmn = 10 then begin
Edit1.SetFocus;
VKClick(VK_H);
tmn := 0;
end;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Button1: TButton;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const
VK_H=72;
var
Form1: TForm1;
tmn: Integer;
implementation
{$R *.dfm}
procedure VKClick(vk: Integer);
begin
KeyBD_Event(vk, MapVirtualKey(vk, 0), 0, 0);
Sleep(10);
KeyBD_Event(vk, MapVirtualKey(vk, 0), KeyEventF_KeyUp, 0);
Sleep(10);
end;
procedure TForm1.Button1Click(Sender: TObject);
const
star = '开始';
stop = '结束';
var
bnm: String;
begin
tmn := 0;
bnm := Button1.Caption;
if bnm = star then begin
Edit1.Text := '';
Timer1.Enabled := True;
bnm := stop;
end else begin
Timer1.Enabled := False;
bnm := star;
end;
Button1.Caption := bnm;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Inc(tmn);
Label1.Caption := IntToStr(tmn);
if tmn = 10 then begin
Edit1.SetFocus;
VKClick(VK_H);
tmn := 0;
end;
end;
end.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询