Advertisement
ChristophX86

Untitled

Aug 16th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 1.90 KB | None | 0 0
  1. #NoTrayIcon
  2.  
  3. Local $GUI, $Text, $Input, $Next, $StartStop, $Display, $Started = False, $RandomString, $Timer, $Time = 0
  4. $GUI = GUICreate("Untitled", 300, 160)
  5. GUISetFont(10, 1000, 0, "Courier New", $GUI)
  6. $Text = GUICtrlCreateLabel('Click "Start" to begin.', 20, 20, 260, 20, 0x01) ; $SS_CENTER
  7. $Input = GUICtrlCreateInput("", 20, 50, 260, 20)
  8. GUICtrlSetState($Input, 256) ; $GUI_FOCUS
  9. $Next = GUICtrlCreateButton("Next", 20, 80, 125, 20)
  10. GUICtrlSetState($Next, 512) ; $GUI_DEFBUTTON
  11. $StartStop = GUICtrlCreateButton("Start", 155, 80, 125, 20)
  12. $Display = GUICtrlCreateLabel("0.0000000000", 20, 120, 260, 20, 0x01) ; $SS_CENTER
  13. GUISetState(@SW_SHOW, $GUI)
  14.  
  15. Do
  16.     Switch GUIGetMsg()
  17.         Case -3 ; $GUI_EVENT_CLOSE
  18.             ExitLoop
  19.         Case $StartStop
  20.             If $Started Then
  21.                 GUICtrlSetData($Text, 'Click "Start" to begin.')
  22.                 GUICtrlSetData($Input, "")
  23.                 GUICtrlSetData($StartStop, "Start")
  24.                 $Started = False
  25.             Else
  26.                 $RandomString = CreateRandomString()
  27.                 GUICtrlSetData($Input, "")
  28.                 GUICtrlSetState($Input, 256) ; $GUI_FOCUS
  29.                 GUICtrlSetData($Text, $RandomString)
  30.                 GUICtrlSetData($StartStop, "Stop")
  31.                 $Started = True
  32.                 $Timer = TimerInit()
  33.             EndIf
  34.         Case $Next
  35.             If $Started And (GUICtrlRead($Input) == $RandomString) Then
  36.                 $Time += TimerDiff($Timer) / StringLen($RandomString)
  37.                 $Time /= 2
  38.                 GUICtrlSetData($Display, $Time)
  39.                 $RandomString = CreateRandomString()
  40.                 GUICtrlSetData($Input, "")
  41.                 GUICtrlSetState($Input, 256) ; $GUI_FOCUS
  42.                 GUICtrlSetData($Text, $RandomString)
  43.                 $Timer = TimerInit()
  44.             EndIf
  45.     EndSwitch
  46. Until False
  47. Exit
  48.  
  49. Func CreateRandomString()
  50.     Local $text = "", $i, $n = Random(4, 8, 1)
  51.     For $i = 1 To $n
  52.         Switch Random(1, 5, 1)
  53.             Case 1, 4
  54.                 $text &= Chr(Random(Asc("A"), Asc("Z"), 1))
  55.             Case 2, 5
  56.                 $text &= Chr(Random(Asc("a"), Asc("z"), 1))
  57.             Case 3
  58.                 $text &= Random(0, 9, 1)
  59.         EndSwitch
  60.     Next
  61.     Return $text
  62. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement