Sign in to follow this  
Followers 0
James

Typing Test

11 posts in this topic

#1 ·  Posted (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.

#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

Share this post


Link to post
Share on other sites



#3 ·  Posted (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 by JamesBrooks

Share this post


Link to post
Share on other sites

lol Nice secretary's training period. I think it should be a case-sensitive test.

Share this post


Link to post
Share on other sites

lol Nice secretary's training period. I think it should be a case-sensitive test.

just change

If $strRead = $strRead2 ThenoÝ÷ ÚÚºÚ"µÍY    ÌÍÜÝXYOH    ÌÍÜÝXY[

Share this post


Link to post
Share on other sites

Take a look at my Type Test :P

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.

Share this post


Link to post
Share on other sites

It's nice but it can be used by those who know english good. For other isn't a correct test. :P

Sentences is some languages would be great.


When the words fail... music speaks

Share this post


Link to post
Share on other sites

lol AlmarM, my average typing speed is 9.5~ second per sentence. Yours best. ;]

Share this post


Link to post
Share on other sites

lol AlmarM, my average typing speed is 9.5~ second per sentence. Yours best. ;]

Hehe :P

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.

Share this post


Link to post
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
Sign in to follow this  
Followers 0