Private Sub Command1_Click()
Static i As Integer
i = i + 1
If i Mod 2 = 0 Then
Command1Caption = "开始"
Timer1Enabled = False
Timer3Enabled = False
End If
If i Mod 2 <> 0 Then
Command1Caption = "暂停"
Randomize
Label1Caption = Chr(Int(25 Rnd + 65))
Randomize
Label1Left = Int(Rnd 4641 + 360)
Label1Top = 360
Timer1Enabled = True
Timer3Enabled = True
End If
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
Randomize
If KeyAscii = Asc(LCase(Label1Caption)) Then Label1Visible = False: Label1Top = 360: Label1Caption = Chr(Int(25 Rnd + 65)): Label1Left = Int(Rnd 4641 + 360): Label1Visible = True: Label5 = Label5 + 10
End Sub
Private Sub Form_Load()
Form1Width = 6855
End Sub
Private Sub Timer1_Timer()
Label1Move Label1Left, Label1Top + 100
If Label1Top > 7800 Then Label1Top = 360: Label1Caption = Chr(Int(25 Rnd + 65)): Label1Visible = True: Label1Left = Int(Rnd 4641 + 360)
End Sub
Private Sub Timer3_Timer()
Static a, c As Integer
a = a + 1
b = 60 - a
Label2Caption = "剩余" & b & "秒"
If b = 0 Then i = MsgBox("是否继续?", 36, "提示")
If i = 6 Then b = 60: a = 0
If i = 7 Then End
End Sub
Dim i As Integer '
Dim zheng As Integer '保存输入正确的值
Dim err1 As Integer '保存输入错误的值
Dim timei As Integer
Private Sub Command1_Click()
Dim name As String
With CommonDialog1
ShowOpen
name = FileName
End With
RichTextBox1LoadFile name
ccrpProgressBar1Max = Len(RichTextBox1Text)
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Command3_Click()
End Sub
Private Sub Form_Load()
ccrpProgressBar1Max = Len(RichTextBox1Text)
i = 1
timei = 0
RichTextBox1SelStart = 3
RichTextBox1SelColor = vbRed
End Sub
Private Sub Text1_Change()
If Len(Text1Text) <> 0 Then
If Mid(RichTextBox1Text, Len(Text1Text), 1) = Mid(Text1Text, Len(Text1Text), 1) Then
RichTextBox1SelStart = i - 1
RichTextBox1SelLength = 1
RichTextBox1SelColor = vbBlue
zheng = zheng + 1
i = i + 1
Else
If i = -1 Then
i = 1
End If
RichTextBox1SelStart = i - 1
RichTextBox1SelLength = 1
RichTextBox1SelColor = vbRed
i = i + 1
err1 = err1 + 1
End If
Else
i = i - 1
RichTextBox1SelStart = 0
RichTextBox1SelLength = 1
RichTextBox1SelColor = &H80000012
End If
If ccrpProgressBar1Value >= Len(Text1Text) Then
MsgBox "ok"
Exit Sub
Else
ccrpProgressBar1Value = Len(Text1Text)
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim rlen As Integer '保存RText的值
Dim tlen As Integer '保存text1的值
If KeyAscii = 8 Then
rlen = Len(RichTextBox1Text)
tlen = Len(Text1Text)
If tlen > 1 Then
RichTextBox1SelStart = tlen - 1
RichTextBox1SelLength = rlen
RichTextBox1SelColor = &H80000012
i = i - 2
End If
End If
If ccrpProgressBar1Value <> 0 Then
ccrpProgressBar1Value = ccrpProgressBar1Value - 1
End If
End Sub
Private Sub Timer1_Timer()
timei = timei + 1
Label2Caption = Int(((Len(Text1Text)) / timei) 60) & "/分"
End Sub
'by dz
可以使用sendkeys()函数
SendKeys 语句
将一个或多个按键消息发送到活动窗口,就如同在键盘上进行输入一样。
语法
SendKeys string[, wait]
SendKeys 语句的语法具有以下几个命名参数:
部分
描述
string
必需的。字符串表达式,指定要发送的按键消息。
Wait
可选的。指定等待方式的 BooleandefBooleanDataType@veendf98chm 值。如果为
False(缺省值),则控件在按键发送出去之后立刻返回到过程。如果为
True,则按键消息必须在控件返回到过程之前加以处理。
说明
每个按键由一个或多个字符表示。为了指定单一键盘字符,必须按字符本身的键。例如,为了表示字母 A,可以用 "A" 作为 string。为了表示多个字符,就必须在字符后面直接加上另一个字符。例如,要表示 A、B 及
C,可用 "ABC" 作为 string。
对 SendKeys 来说,加号 (+)、插入符 (^)、百分比符号
(%)、上划线 (~) 及圆括号 ( ) 都具有特殊意义。为了指定上述任何一个字符,要将它放在大括号 ({})
当中。例如,要指定正号,可用 {+} 表示。方括号 ([ ]) 对 SendKeys
来说并不具有特殊意义,但必须将它们放在大括号中。在其它应用程序中,方括号有特殊意义,在出现动态数据交换 (DDE) 的时候,它可能具有重要意义。为了指定大括号字符,请使用
{{} 及 {}}。
为了在按下按键时指定那些不显示的字符,例如 ENTER 或 TAB
以及那些表示动作而非字符的按键,请使用下列代码:
按键
代码
BACKSPACE
{BACKSPACE}, {BS}, 或
{BKSP}
BREAK
{BREAK}
CAPS LOCK
{CAPSLOCK}
DEL or DELETE
{DELETE} 或 {DEL}
DOWN ARROW
{DOWN}
END
{END}
ENTER
{ENTER}或 ~
ESC
{ESC}
HELP
{HELP}
HOME
{HOME}
INS or INSERT
{INSERT} 或 {INS}
LEFT ARROW
{LEFT}
NUM LOCK
{NUMLOCK}
PAGE DOWN
{PGDN}
PAGE UP
{PGUP}
PRINT SCREEN
{PRTSC}
RIGHT ARROW
{RIGHT}
SCROLL LOCK
{SCROLLLOCK}
TAB
{TAB}
UP ARROW
{UP}
F1
{F1}
F2
{F2}
F3
{F3}
F4
{F4}
F5
{F5}
F6
{F6}
F7
{F7}
F8
{F8}
F9
{F9}
F10
{F10}
F11
{F11}
F12
{F12}
F13
{F13}
F14
{F14}
F15
{F15}
F16
{F16}
为了指定那些与 SHIFT、CTRL 及 ALT
等按键结合的组合键,可在这些按键码的前面放置一个或多个代码,这些代码列举如下:
按键
代码
SHIFT
+
CTRL
^
ALT
%
为了说明在按下其它按键时应同时按下 SHIFT、CTRL、及 ALT
的任意组合键,请把那些按键的码放在括号当中。例如,为了说明按下 E 与 C 的时候同时按下 SHIFT 键,请使用
"+(EC)"。为了说明在按下 E 的时候同时按下 SHIFT 键,但接着按 C 而不按 SHIFT,则使用
"+EC"。
为了指定重复键,使用 {key number} 的形式。必须在 key 与
number 之间放置一个空格。例如,{LEFT 42} 意指 42 次按下 LEFT ARROW 键;{h 10} 则是指 10 次按下 H 键。
注意 不能用 SendKeys
将按键消息发送到这样一个应用程序,这个应用程序并没有被设计成在 Microsoft Windows 中运行。Sendkeys
也无法将 PRINT SCREEN 按键 {PRTSC}
发送到任何应用程序。
SendKeys 语句示例
本示例使用 Shell 函数来运行 Microsoft Windows 所附的计算器程序;然后使用
SendKeys 语句来按下计算器的某些数字键,最后退出计算器。(若要观察示例运行过程,可将示例粘贴到过程中,再运行过程即可。因为
AppActivate 会将焦点转移到计算器应用程序,故本示例不能以单步方式来运行。)。
Dim ReturnValue, I
ReturnValue = Shell("CalcEXE", 1) ' 运行计算器。
AppActivate ReturnValue ' 激活计算器。
For I = 1 To 100 ' 设置计数循环。
SendKeys I & "{+}", True ' 按下按键给计算器
Next I ' 将所有 I 值相加。
SendKeys "=", True ' 取得总合。
SendKeys "%{F4}", True ' 按 ALT+F4 关闭计算器。
我可以给你一个小例子!
如果你要全部按照你的要求完成,你得花钱找人做了!~
例子程序可以去我资料里找我网盘的地址,然后在里面可以找到Tpyingrar
Option Explicit
Dim score As Integer
Dim speed As Integer
Dim Wrong As Integer
Sub init()
Label1Caption = Chr(Int(Rnd 26) + 49)
speed = Int(Rnd 100 + Val(Label7Text))
Label1Left = Int(Rnd Frame1Width)
Label1Top = Frame1Top
Wrong = Wrong + 1
End Sub
Private Sub Command1_Click()
Wrong = 0
score = 0
init
Timer1Enabled = True
Timer2Enabled = True
Command1Visible = False
Label4Caption = 0
Label5Enabled = False
Label7Enabled = False
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
If Chr(KeyAscii) = Label1Caption Then
init
score = score + 1
Label4Caption = score
End If
End Sub
Private Sub Form_Load()
Randomize
Timer1Enabled = False
Timer2Enabled = False
End Sub
Private Sub Timer1_Timer()
Label1Top = Label1Top + speed
If Label1Top > Frame1Height Then
init
End If
End Sub
Private Sub Timer2_Timer()
Label5Text = Val(Label5Text) - 1
If Val(Label5Text) <= 0 Then
Timer1Enabled = False
Label1Caption = ""
MsgBox (score / Wrong) 100 & "%"
Command1Visible = True
Label4Caption = 0
Label5Text = 60
Label5Enabled = True
Label7Enabled = True
Timer1Enabled = False
Timer2Enabled = False
End If
End Sub
VERSION 500
Begin VBForm Form1
Caption = "英文打字"
ClientHeight = 8295
ClientLeft = 60
ClientTop = 450
ClientWidth = 7815
LinkTopic = "Form1"
ScaleHeight = 8295
ScaleWidth = 7815
StartUpPosition = 3 '窗口缺省
Begin VBCommandButton Command1
Caption = "Command1"
Height = 855
Left = 2160
TabIndex = 3
Top = 4680
Width = 2775
End
Begin VBTextBox Text1
BeginProperty Font
Name = "宋体"
Size = 42
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 1230
Left = 3480
TabIndex = 1
Text = "Text1"
Top = 1560
Width = 2895
End
Begin VBLabel Label3
Caption = "得分:"
BeginProperty Font
Name = "宋体"
Size = 36
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 855
Left = 840
TabIndex = 4
Top = 240
Width = 2175
End
Begin VBLabel Label2
AutoSize = -1 'True
Caption = "Label2"
BeginProperty Font
Name = "宋体"
Size = 36
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 720
Left = 3240
TabIndex = 2
Top = 300
Width = 2760
End
Begin VBLabel Label1
Caption = "Label1"
BeginProperty Font
Name = "宋体"
Size = 42
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF00FF&
Height = 1095
Left = 480
TabIndex = 0
Top = 1628
Width = 2895
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
If Trim(Label1) = Trim(Text1) Then Label2 = Label2 + 5
Label1 = Chr(Asc("A") + Rnd(1) 25) & Chr(Asc("A") + Rnd(1) 25) & Chr(Asc("A") + Rnd(1) 25) & Chr(Asc("A") + Rnd(1) 25) & Chr(Asc("A") + Rnd(1) 25)
Text1 = ""
End Sub
Private Sub Form_Load()
Randomize (Second(Now()))
Label2 = "0"
Label1 = Chr(Asc("A") + Rnd(1) 25) & Chr(Asc("A") + Rnd(1) 25) & Chr(Asc("A") + Rnd(1) 25) & Chr(Asc("A") + Rnd(1) 25) & Chr(Asc("A") + Rnd(1) 25)
Text1 = ""
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Or Len(Text1) = 5 Then Call Command1_Click
Text1 = Trim(Text1 & UCase$(Chr(KeyAscii)))
KeyAscii = 0
End Sub
'将以上内容保存为 form1frm 用VB打开就可以
以上就是关于英文打字练习的完整VB程序代码全部的内容,包括:英文打字练习的完整VB程序代码、简单打字练习VB代码、用VB编写程序向其他程序光标闪动处中输入文字等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)