定时模拟键盘按键

object Form1: TForm1
  Left = 192
  Top = 114
  Width = 497
  Height = 292
  Caption = #33258#21160#25353#38190#8212#8212#23567#24069#30340#21019#24847
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Label2: TLabel
    Left = 48
    Top = 16
    Width = 65
    Height = 17
    AutoSize = False
    Caption = #35774#23450#39029#25968
  end
  object Label3: TLabel
    Left = 36
    Top = 48
    Width = 89
    Height = 13
    AutoSize = False
    Caption = #25353#19979'F1'#21518#65292#36807
  end
  object Label4: TLabel
    Left = 216
    Top = 48
    Width = 73
    Height = 17
    AutoSize = False
    Caption = 'ms'#25353#19979'Enter'
  end
  object Label5: TLabel
    Left = 104
    Top = 72
    Width = 25
    Height = 17
    AutoSize = False
    Caption = #36807
  end
  object Label6: TLabel
    Left = 216
    Top = 72
    Width = 97
    Height = 17
    AutoSize = False
    Caption = 'ms'#20877#25353#19979'Enter'
  end
  object Label1: TLabel
    Left = 104
    Top = 96
    Width = 25
    Height = 25
    AutoSize = False
    Caption = #36807
  end
  object Label7: TLabel
    Left = 216
    Top = 104
    Width = 97
    Height = 13
    AutoSize = False
    Caption = 'ms'#37325#26032#25353#19979'F1'
  end
  object Button1: TButton
    Left = 344
    Top = 112
    Width = 105
    Height = 41
    Caption = #24320#22987
    TabOrder = 0
    OnClick = Button1Click
  end
  object Edit1: TEdit
    Left = 128
    Top = 8
    Width = 81
    Height = 21
    TabOrder = 1
  end
  object Edit2: TEdit
    Left = 128
    Top = 40
    Width = 81
    Height = 21
    TabOrder = 2
    Text = '2000'
  end
  object Edit3: TEdit
    Left = 128
    Top = 72
    Width = 81
    Height = 21
    TabOrder = 3
    Text = '6000'
  end
  object Button2: TButton
    Left = 120
    Top = 144
    Width = 105
    Height = 33
    Caption = #35774#23450#20197#19978#21442#25968
    TabOrder = 4
    OnClick = Button2Click
  end
  object Edit4: TEdit
    Left = 128
    Top = 96
    Width = 81
    Height = 21
    TabOrder = 5
    Text = '1000'
  end

end


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Label2: TLabel;
    Edit2: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    Edit3: TEdit;
    Label5: TLabel;
    Label6: TLabel;
    Button2: TButton;
    Edit4: TEdit;
    Label1: TLabel;
    Label7: TLabel;
    procedure Button1Click(Sender: TObject);

    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
 
   
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
      //i:integer;//模拟按键时间
      pages:integer;//页数
      time1 :integer;
      time2 :integer;
      time3 :integer;
       times :integer;//执行次数
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
label
J;
begin
 J:
 sleep(time3);
 keybd_event($70,0,KEYEVENTF_EXTENDEDKEY     or 0,0);//$70是F1键的虚拟键值,
 keybd_event($70,0,KEYEVENTF_EXTENDEDKEY     or     KEYEVENTF_KEYUP,0);  //F1按下弹起
 sleep(time1);
   keybd_event(13,0,KEYEVENTF_EXTENDEDKEY     or     0,0);
  keybd_event(13,0,KEYEVENTF_EXTENDEDKEY     or     KEYEVENTF_KEYUP,0);  //回车键按下弹起
  sleep(time2);
    keybd_event(13,0,KEYEVENTF_EXTENDEDKEY     or     0,0);
  keybd_event(13,0,KEYEVENTF_EXTENDEDKEY     or     KEYEVENTF_KEYUP,0);  //回车键按下弹起

  times:=times+1;
if times>=pages then
begin
Button1.Enabled:=false;
 Exit;
end
else
begin
goto J;
end;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin

times :=0;
Button1.Enabled :=false;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
try
times :=0;
 pages:=StrToInt(Edit1.Text);
 time1:=StrToInt(Edit2.Text);
 time2:=StrToInt(Edit3.Text);
 time3:=StrToInt(Edit4.Text);
 Button1.Enabled:=true;
except
 Button1.Enabled:=false;
  Showmessage('设置出错!');

end;

end;


end.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值