• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

小键盘练习程序delphi版

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

源代码:

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

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.

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

界面代码:

object Form1: TForm1
  Left = 0
  Top = 0
  BorderIcons = [biSystemMenu, biMinimize]
  Caption = #23567#38190#30424#32451#20064'  '#29482#24735#33021
  ClientHeight = 252
  ClientWidth = 390
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnShow = FormShow
  PixelsPerInch = 96
  TextHeight = 13
  object Label2: TLabel
    Left = 24
    Top = 8
    Width = 3
    Height = 13
  end
  object Label1: TLabel
    Left = 24
    Top = 49
    Width = 8
    Height = 29
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clRed
    Font.Height = -24
    Font.Name = 'Tahoma'
    Font.Style = []
    ParentFont = False
  end
  object Edit1: TEdit
    Left = 24
    Top = 120
    Width = 353
    Height = 41
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clBlue
    Font.Height = -19
    Font.Name = 'Tahoma'
    Font.Style = []
    ParentFont = False
    TabOrder = 0
    OnKeyPress = Edit1KeyPress
  end
  object Button1: TButton
    Left = 208
    Top = 203
    Width = 81
    Height = 30
    Caption = #24320#22987
    TabOrder = 1
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 295
    Top = 203
    Width = 82
    Height = 30
    Caption = #36864#20986
    TabOrder = 2
    OnClick = Button2Click
  end
end
 

源代码下载:http://www.rayfile.com/files/03ca62e3-14ff-11df-b22f-0015c55db73d/


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
matlab导入txt数据画图发布时间:2022-07-18
下一篇:
Matlab批量绘制图像并保存发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap