James Posted February 17, 2009 Share Posted February 17, 2009 (edited) Hey all, Well this came out of bored. I wasn't even paying attention to what I was typing for a good majority of it. This is a typing test, click start and then type straight away! Different sentences are held in a 2D array. The first dimension holds the sentence while the second holds the amount of words in the sentence. When you have finished typing press Enter. The script then calculates the time it took and the WPM. expandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Dim $isRun = False, $intDex Dim $arrWords[6][2] = [["The quick brown fox jumps over the lazy dog", 9], ["This is a sentence", 4], _ ["Twinkle twinkle little star, how I wonder what you are", 10], ["A new computer is sold in the US every hour!", 10], _ ["When do birds migrate from North to South?", 8], ["If you can correctly, and quickly, type this perplexing sentence, you are one superb typist!", 15]] $GUI = GUICreate("Typing Test", 312, 175) $hwnd = WinGetHandle($GUI) $strInput = GUICtrlCreateInput("", 8, 104, 274, 21) $strText = GUICtrlCreateEdit("", 8, 8, 297, 89, BitOR($ES_AUTOVSCROLL,$ES_WANTRETURN,$WS_VSCROLL)) $btnStart = GUICtrlCreateButton("Start", 8, 130, 60, 40) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnStart GUICtrlSetBkColor($strInput, $GUI_BKCOLOR_TRANSPARENT) $arrBound = UBound($arrWords) - 1 $intDex = Random(0, $arrBound) GUICtrlSetData($strText, $arrWords[$intDex][0]) GUICtrlSetData($strInput, "") ControlFocus($hwnd, "", ControlGetHandle($hwnd, "", 3)) $tmeCount = TimerInit() $isRun = True Case $strInput If $isRun = True Then $tmeDiff = TimerDiff($tmeCount) $strRead = GUICtrlRead($strInput) $strRead2 = GUICtrlRead($strText) $tmeDiff = Round((($tmeDiff) / 1000), 2) $numSpeed = Round(($arrWords[$intDex][1]/$tmeDiff) * 60) If $strRead = $strRead2 Then GUICtrlSetBkColor($strInput, 0x00ff00) MsgBox(0, "Typing Test", "You took, " & $tmeDiff & " seconds; which is a typing speed of, " & $numSpeed & "WPM.") Else GUICtrlSetBkColor($strInput, 0xff0000) MsgBox(0, "Typing Test", "You made an error but typed at " & $numSpeed & "WPM.") EndIf $isRun = False EndIf EndSwitch WEnd Have fun. James Edited February 17, 2009 by JamesBrooks Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
James Posted February 17, 2009 Author Share Posted February 17, 2009 (edited) Spot the mistake - Fixed. Edited February 17, 2009 by JamesBrooks Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
James Posted March 13, 2009 Author Share Posted March 13, 2009 (edited) Update: CODE#NoTrayIcon ;~ Typing Test ;~ Test your skillz to the max ;~ Written by James Brooks 2009 #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> Dim $isRun = False, $intDex, $strWordSize Dim $arrWords[1] ; Dim $fleList = FileOpenDialog("Typing Test - Select a test", @ScriptDir & '\data', "INI (*.ini)") Dim $fleList = @ScriptDir & '\data.ini' _GenerateData($fleList) HotKeySet("{F3}", "_DisplayArray") $GUI = GUICreate("Typing Test", 312, 175) $hwnd = WinGetHandle($GUI) $strInput = GUICtrlCreateInput("", 8, 104, 274, 21) $strText = GUICtrlCreateEdit("", 8, 8, 297, 89, BitOR($ES_AUTOVSCROLL,$ES_WANTRETURN,$WS_VSCROLL)) $btnStart = GUICtrlCreateButton("Start", 8, 130, 60, 40) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnStart GUICtrlSetBkColor($strInput, $GUI_BKCOLOR_TRANSPARENT) $arrBound = UBound($arrWords) - 1 $intDex = Random(1, $arrBound) $strWordSize = StringSplit($arrWords[$intDex], " ") ConsoleWrite($strWordSize[0] & @CRLF) MsgBox(0, "Typing Test", "The test will start as soon as you press OK!") GUICtrlSetData($strText, $arrWords[$intDex]) GUICtrlSetData($strInput, "") ControlFocus($hwnd, "", ControlGetHandle($hwnd, "", 3)) $tmeCount = TimerInit() $isRun = True Case $strInput If $isRun = True Then $tmeDiff = TimerDiff($tmeCount) $strRead = GUICtrlRead($strInput) $strRead2 = GUICtrlRead($strText) $tmeDiff = Round((($tmeDiff) / 1000), 2) $numSpeed = Round(($strWordSize[0]/$tmeDiff) * 60) If $strRead = $strRead2 Then GUICtrlSetBkColor($strInput, 0x00ff00) MsgBox(0, "Typing Test", "You took, " & $tmeDiff & " seconds; which is a typing speed of, " & $numSpeed & "WPM.") Else GUICtrlSetBkColor($strInput, 0xff0000) MsgBox(0, "Typing Test", "You made an error but typed at " & $numSpeed & "WPM.") EndIf $isRun = False EndIf EndSwitch WEnd ;~ Generate the array with all possible sentences Func _GenerateData($io_File) $iniNames = IniReadSectionNames($io_File) For $i = 1 To $iniNames[0]; Generate each section name $iniSection = IniReadSection($io_File, $iniNames[$i]) For $j = 1 To $iniSection[0][0] ;~ ConsoleWrite($i & " = " & $iniSection[$j][1] & @CRLF) _ArrayAdd($arrWords, $iniSection[$j][1]) Next Next EndFunc ;~ Display the array at any time Func _DisplayArray() If WinActive($hwnd) Then _ArrayDisplay($arrWords) EndFunc ;~ Display a custom message box (Smoke_N) Func _MsgBoxEx($iFlag, $sTitle, $sText, $iTime = 0, $sCIDChange = '') Local $_MsgBox_ = '"' & "ConsoleWrite(MsgBox(" & $iFlag & ', ""' & $sTitle & '"", ""' & $sText & '"", ' & $iTime & '"))' Local $iPID = Run(@AutoItExe & ' /AutoIt3ExecuteLine ' & $_MsgBox_, '', @SW_SHOW, 6) Do Sleep(10) Until WinExists($sTitle) If IsArray($sCIDChange) Then For $iCC = 1 To UBound($sCIDChange) - 1 ControlSetText($sTitle, '', 'Button' & $iCC, $sCIDChange[$iCC]) Next Else ControlSetText($sTitle, '', 'Button1', $sCIDChange) EndIf While ProcessExists($iPID) Local $iStdOut = StdoutRead($iPID) If Number($iStdOut) Then Return $iStdOut Sleep(10) WEnd If IsArray($sCIDChange) Then Return SetError(1, 0, 2) Return SetError(1, 0, 1) EndFunc And the INI file (data.ini): [Type1] Sentence=The quick brown fox jumps over the lazy dog [Type2] Sentence=This is a sentence [Type3] Sentence=Twinkle twinkle little star, how I wonder what you are [Type4] Sentence=A new computer is sold in the US every hour! [Type5] Sentence=When do birds migrate from North to South? [Type6] Sentence=If you can correctly, and quickly, type this perplexing sentence, you are one superb typist! Edited March 13, 2009 by JamesBrooks Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Authenticity Posted March 13, 2009 Share Posted March 13, 2009 lol Nice secretary's training period. I think it should be a case-sensitive test. Link to comment Share on other sites More sharing options...
PhilRip Posted March 13, 2009 Share Posted March 13, 2009 lol Nice secretary's training period. I think it should be a case-sensitive test. just change If $strRead = $strRead2 ThenoÝ÷ ÚÚºÚ"µÍY ÌÍÜÝXYOH ÌÍÜÝXY[ Link to comment Share on other sites More sharing options...
James Posted March 13, 2009 Author Share Posted March 13, 2009 Thanks Authenticity I may add an option to do that. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
AlmarM Posted March 13, 2009 Share Posted March 13, 2009 Take a look at my Type Test AlmarM Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
Andreik Posted March 13, 2009 Share Posted March 13, 2009 It's nice but it can be used by those who know english good. For other isn't a correct test. Sentences is some languages would be great. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Authenticity Posted March 13, 2009 Share Posted March 13, 2009 lol AlmarM, my average typing speed is 9.5~ second per sentence. Yours best. ;] Link to comment Share on other sites More sharing options...
James Posted March 13, 2009 Author Share Posted March 13, 2009 You can obviously change the text in the INI file. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
AlmarM Posted March 14, 2009 Share Posted March 14, 2009 lol AlmarM, my average typing speed is 9.5~ second per sentence. Yours best. ;]Hehe AlmarM Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now