Click here to Skip to main content
15,885,869 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
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?
Posted
Updated 30-Jun-14 10:06am
v3
Comments
ZurdoDev 30-Jun-14 15:55pm    
This is a repost. Why are you asking again?
KD Palekar 30-Jun-14 16:06pm    
that post was related to if there is only one minute but tell me how to count the words typed by the way if there are 10 minutes?
ZurdoDev 30-Jun-14 16:08pm    
x 10.
KD Palekar 30-Jun-14 16:14pm    
???? What is this?
ZurdoDev 30-Jun-14 16:18pm    
If you have the code to count per 1 minute how come you can't adjust it to work for 10 minutes?

1 solution

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
 
Share this answer
 
v2
Comments
DamithSL 30-Jun-14 22:57pm    
Better approach, 5wd
Sergey Alexandrovich Kryukov 30-Jun-14 23:16pm    
Thank you, Damith.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900