【发布时间】:2016-02-01 10:38:42
【问题描述】:
我试图计算用户键入时每毫秒字符的键入速度。我有两个控件,richtextbox 和 textbox 作为输入区域,当用户在文本区域输入时,字符之间的速度会显示在 Richtextbox 中。
Public Class Form1
Dim swatch As New Stopwatch
Dim finalSpeed As Double
Dim temp As Double
Private Sub typingArea_KeyPressed(sender As Object, e As KeyPressEventArgs) Handles typingArea.KeyPress
swatch.Start()
If swatch.IsRunning Then
temp += swatch.ElapsedMilliseconds
End If
If e.KeyChar = ChrW(Keys.Return) Then
e.KeyChar = Nothing
swatch.Reset()
MsgBox(finalSpeed / typingArea.Text.Length)
typingArea.Text = Nothing
logArea.Text = Nothing
End If
If typingArea.Text <> Nothing Then
swatch.Start()
End If
If swatch.IsRunning = False Then swatch.Start()
If typingArea.Text.Length > 0 Then
logArea.AppendText("time between two chars is " + temp.ToString() + Environment.NewLine)
finalSpeed += temp
temp = 0
swatch.Restart()
'End If
Else
swatch.Reset()
End If
End Sub
Public Function returnAverageSpeed(ByVal length As Integer, ByVal total As Double) As Double
Return total / length
End Function
End Class
如果文本框中只有一个字符,则无需计算速度,但如果用户键入第二个字符和后续字符,则我们开始计算速度。如果用户按下回车键,我们计算的平均速度将停止该过程,直到用户再次开始在文本框中输入。这里的问题是,程序无法记录第一个字符和第二个字符之间的速度,但其他字符现在似乎工作正常。
【问题讨论】:
-
您是否意识到,您在输入每个字符时都使用微积分更新标签这一事实会使您的度量的正确性无效?
-
FWIW - 世界上最快的打字员每分钟输入 216 个单词。平均单词是 5 个字符加上一个用于分隔符。这意味着每毫秒的字符数小于整个字符。
标签: .net vb.net visual-studio-2012