#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
Global $Edit, $ExitTest = -1, $Timer, $Lab, $Fehler = 0, $DelCount = 0

$gui = GUICreate("WriteTest by Sprenger120", 170, 60, -1, -1)
$StartTest = GUICtrlCreateButton("Start Test", 16, 16, 145, 33, 0)
GUISetState(@SW_SHOW)
While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $StartTest
			_WinSetSize($gui, 523, 300, 1)
			GUICtrlSetPos($StartTest, 11, 11, 145, 33)
			GUICtrlSetState($StartTest, $GUI_DISABLE)
			$Edit = GUICtrlCreateEdit("", 8, 160, 505, 105, 0, -1)
			GUICtrlSetState(-1, $GUI_DISABLE)
			GUICtrlCreateLabel("Diesen Test bitte unten reinschreiben.", 8, 56, 183, 17)
			$Lab = GUICtrlCreateLabel("Es ist mir ein Vergnügen, Sie in unserem bescheidenen Haus zu begrüßen. Wenn Sie mir bitte folgen würden, der Lord erwartet Sie bereits.", 8, 80, 509, 64)
			GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
			MsgBox(64, "Info", "Bitte den Text ein mal komplett durchlesen. Der Test startet wenn das Schreibfeld freigegeben wird.")
			Sleep(10000)
			_WinAPI_MessageBeep()
			GUICtrlSetState($Edit, $GUI_ENABLE)
			GUICtrlSetState($Edit, $GUI_FOCUS)
			$Timer = TimerInit()
			HotKeySet("{BACKSPACE} ", "DelCount")
			HotKeySet("{DELete}", "DelCount")
			AdlibRegister("Update", 50)
	EndSwitch
WEnd

Func Update()
	If StringLen(GUICtrlRead($Edit)) = StringLen(GUICtrlRead($Lab)) Then
		AdlibUnRegister()
		HotKeySet("{Delete}")
		HotKeySet("{BACKSPACE}")
		GUISetState(@SW_LOCK, $gui)
		Do
			If StringLen(GUICtrlRead($Edit)) > StringLen(GUICtrlRead($Lab)) Then GUICtrlSetData($Edit, StringTrimRight(GUICtrlRead($Edit), 1))
		Until StringLen(GUICtrlRead($Edit)) = StringLen(GUICtrlRead($Lab))

		$Timer = TimerDiff($Timer)
		$Timer = $Timer / 1000
		$len = StringLen(GUICtrlRead($Edit))

		$Lab = StringSplit(GUICtrlRead($Lab), "")
		$UserEing = StringSplit(GUICtrlRead($Edit), "")


		For $x = 1 To $Lab[0]
			If $Lab[$x] <> $UserEing[$x] Then $Fehler += 1
		Next

		MsgBox(0, 0, "Du schreibst: " & Round($len / $Timer, 1) & " Zeichen pro Sekunde." & @CRLF & "Du hast: " & $Fehler & " Abschreibfehler." & @CRLF & "Du hast: " & $DelCount & " mal deine Eingabe verändert.")
		Exit
	EndIf
EndFunc   ;==>Update

Func DelCount()
	$DelCount += 1
	GUICtrlSetData($Edit, StringTrimRight(GUICtrlRead($Edit), 1))
EndFunc   ;==>DelCount


;By GtaSpider
Func _WinSetSize($hWnd, $iWidth, $iHeigth, $iSleep = -1, $iStep = 4)
	If $iSleep < 0 Then Return WinMove($hWnd, "", Default, Default, $iWidth, $iHeigth)
	Local $i, $iStepW = $iStep, $iStepH = $iStep, $iSin, $i2, $iLastI
	Local $aWinPos = WinGetPos($hWnd)
	If $iWidth < $aWinPos[2] Then $iStepW *= -1
	If $iHeigth < $aWinPos[3] Then $iStepH *= -1
	Local $iDegToRad = 3.14159265358979 / 180
	Local $iSinMulW = ($iWidth - $aWinPos[2]) / 2.5
	Local $iSinMulH = ($iHeigth - $aWinPos[3]) / 2.5
	If $iSinMulW < 0 Then $iSinMulW *= -1
	If $iSinMulH < 0 Then $iSinMulH *= -1
	If $iWidth <> $aWinPos[2] Then
		For $i = $aWinPos[2] To $iWidth Step $iStepW
			$iLastI = $i
			$iSin = $i - $aWinPos[2]
			$iSin = Sin($iDegToRad * (180 * $iSin / ($iWidth - $aWinPos[2])))
			WinMove($hWnd, "", Default, Default, $i + ($iSin * $iSinMulW), Default)
			Sleep($iSleep)
		Next
		If Mod($iWidth - $aWinPos[2], $iStep) Then
			If $iStepW < 0 Then
				$iStepW = -1
			Else
				$iStepW = 1
			EndIf
			For $i = $iLastI - 1 To $iWidth Step $iStepW
				WinMove($hWnd, "", Default, Default, $i, Default)
			Next
		EndIf
	EndIf
	If $iHeigth <> $aWinPos[3] Then
		For $i = $aWinPos[3] To $iHeigth Step $iStepH
			$iLastI = $i
			$iSin = $i - $aWinPos[3]
			$iSin = Sin($iDegToRad * (180 * $iSin / ($iHeigth - $aWinPos[3])))
			WinMove($hWnd, "", Default, Default, Default, $i + ($iSin * $iSinMulH))
			Sleep($iSleep)
		Next
		If Mod($iHeigth - $aWinPos[3], $iStep) Then
			If $iStepH < 0 Then
				$iStepH = -1
			Else
				$iStepH = 1
			EndIf
			For $i = $iLastI - 1 To $iHeigth Step $iStepH
				WinMove($hWnd, "", Default, Default, Default, $i)
			Next
		EndIf
	EndIf
EndFunc   ;==>_WinSetSize
