Jump to content

Typing Test


James
 Share

Recommended Posts

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.

#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 by JamesBrooks
Link to comment
Share on other sites

  • 4 weeks later...

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 by JamesBrooks
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...