如何计算用户每分钟输入的字数I.e. WPM? [英] how to calculate the number ofwords typed by the user per minute I.e. wpm?

查看:182
本文介绍了如何计算用户每分钟输入的字数I.e. WPM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设计时器设置为10分钟,那么我如何计算用户每分钟输入的

字数。 wpm?

suppose the timer is set to the 10 minutes then how can I calculate the number of
words typed by the user per minute I.e. wpm?

推荐答案

请参阅我对该问题的评论。你的错误是使用计时器并试图处理它的事件。要实现所需,您需要反转处理:代替计时器事件,处理键盘事件。想一想:事件的真正来源是键盘事件,因为你想要打字时间。你根本不需要任何计时器。



你实际上只有三种事件:1)开始计时; 2)当用户键入这些单词时,每个键上的键盘事件; 3)结束时间。使用 System.Diagnostics.Stopwatch 的实例,重置并在第一个事件中启动它,在第三个事件中停止:

http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx [ ^ ] ,

http://msdn.microsoft.com/en -us / library / system.diagnostics.stopwatch.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.reset.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.start.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch .restart.aspx [ ^ ],

http ://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.stop.aspx [ ^ ]。br />


经过的时间将是你的秒表。已经

http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.elapsed .aspx [ ^ ]。



现在,您需要查找在此期间键入的单词数量。当用户键入空格,制表符或任何标点字符(包括例如行尾)时,该单词结束。如果只想要包含字符的单词,请测试键入的字符是否不是字母(见下文)。当时间停止时,可以计算最后一个字(但它可能是不完整的字,所以考虑到它是否是一个哲学问题:-))。处理事件 KeyPress

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress%28v=vs.110% 29.aspx [ ^ ]。



要对单词或非单词中的键入字符进行分类,请使用 System.Char ,例如:

http://msdn.microsoft.com/en-us/library/6w3ahtyy.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/cta536cf.aspx [ ^ ],

http:// msdn。 microsoft.com/en-us/library/yyxz6h5w.aspx [ ^ ]。



除以已用时间计算的字数。 :-)



-SA
Please see my comments to the question. Your mistake is using the timer and trying to handle its events. To achieve what you need, you need to invert the processing: instead of timer events, handle keyboard events. Think about it: the real source of events is the keyboard events, as you want to time typing. You won't need any timer at all.

You actually have only three kinds of events: 1) start of timing; 2) keyboard events on each key when the user types those words; 3) end of timing. Use an instance of System.Diagnostics.Stopwatch, reset and start it on first event, stop in on third event:
http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.reset.aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.start.aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.restart.aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.stop.aspx[^].

The elapsed time will be your Stopwatch.Elapsed:
http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.elapsed.aspx[^].

Now, you need to find how many words was typed during this time. The word is finished when a user types a blank space, tab or any punctuation character, including, say, end of line. If you want only the word containing only the character, test if the typed character is not letter (see below). The last word can be counted when timing has stopped (but it could be incomplete word, so taking it into account or not is a philosophical question :-)). Handle the event KeyPress:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress%28v=vs.110%29.aspx[^].

To classify typed characters in word or non-word, uses the methods of System.Char, such as:
http://msdn.microsoft.com/en-us/library/6w3ahtyy.aspx[^],
http://msdn.microsoft.com/en-us/library/cta536cf.aspx[^],
http://msdn.microsoft.com/en-us/library/yyxz6h5w.aspx[^].

Divide number of counted words by elapsed time. :-)

—SA


这篇关于如何计算用户每分钟输入的字数I.e. WPM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆