RSS订阅 | 匿名投稿
您的位置:网站首页 > 键盘 > 正文

小键盘练习程序delphi版

作者:admin 来源:未知 日期:2010/5/9 14:48:08 人气: 标签:

源代码:

-------------------------------------------------------------------------

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Label2: TLabel;
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    procedure FormShow(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
  *******
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  js:integer;
  keysum:integer;
  flage:Boolean;
  hThread1:THandle;
  function rndsum():integer;stdcall;
implementation

{$R *.dfm}
//{$APPTYPE CONSOLE}

function rndsum():integer;stdcall;
var
  i: Integer;
  sum1: Integer;
  str1: string;
  str2: string;
begin
  sum1:=14;

  while True do
  begin
    if flage then
    begin
      flage:=false;
      Randomize;
      str1:='';
      str2:='';
      for i := 0 to sum1-1  do
      begin
        str1:=chr(48+Random(10));
        str2:=str2+str1;
      end;
      form1.Label1.Caption:=str2;
    end
    else
    begin
      sleep(10);
    end;


  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  id: DWORD;
begin
//产生随机数线程
flage:=true;
hThread1:=CreateThread(nil,0,@rndsum,nil,0,id);
if(hThread1=0) then
begin
  ShowMessage('线程创建失败!');
  exit;
end;
//光标定位
form1.Edit1.SetFocus;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  I: Integer;
begin
  halt;

end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var
  c1: string;
  oldstr: string;
begin
  //只能输入数字
  if not (key in ['0'..'9',#8]) then
  begin
    key := #0;
    exit;
  end;

  c1:=form1.Label1.Caption;
  inc(js);
  if(midstr(c1,js,1)<>key) then //按错了
  begin
    dec(js);
    beep;
    key:=#0;
    exit;
  end;
  inc(keysum);

  if(js>=14) then
  begin
    js:=0;
    form1.Edit1.Text:='';
    key:=#0;
    flage:=true;
    sleep(1);
  end;


  form1.Label2.Caption:='击键次数:'+inttostr(keysum);

end;

procedure TForm1.FormShow(Sender: TObject);
begin
//初始化变量
js:=0;
keysum:=0;
flage:=false;
form1.Label1.Font.Name:='Arial Black';
form1.Label1.Font.Height:=52;
form1.Edit1.Font.Name:='Arial Black';
form1.Edit1.Font.Height:=52;

end;

end.


读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址:
上一篇:Delphi AllocMem