So a pseudo-thread would mean calling another script from the commandline? eg:
I've updated the code below with the above function and it was indeed faster. Is there any way to do this without writing a file to the hard drive, using a stream or virtual file in ram or maybe passing the function text directly to an AutoHotkey DLL?
Code: Select all
;SpellingTutor
UniqueIdentifier := "Spelling Tutor " . A_TickCount
GetWordsList(WordsList, "Paste or Type in a list of words and press Enter or click OK")
WordsWrongThisSession := 0
WordsCorrectThisSession := 0
WordCount := 0
; Transform your linebreak-separated list into array:
WordArray := []
Loop, Parse, Wordslist, `n
WordArray[A_Index - 1] := A_LoopField
Gui, InputBox:Add, Edit, x22 y69 w360 h20 vUserInput,
Gui, InputBox:Add, Button, x22 y29 w100 h30 gSayWordBtn, Say Word
Gui, InputBox:Add, Button, x322 y109 w100 h30 gCheckSpellingBtn Default, Check Spelling
Gui, InputBox:Add, Button, x22 y149 w100 h30 gShowWordBtn, Show Word
Gui, InputBox:Add, Text, x23 y109 w290 h30 vSpellCheckMessage, Enter The Word You Heard
Gui, InputBox:Add, Text, x22 y189 w360 h30 vCorrectSpelling,
hIcon := LoadPicture("imageres.dll", "w32 Icon182", _)
Gui, InputBox:Add, Picture, x392 y69 w20 h20 vIconPic, % "HICON:" hIcon
Gui, InputBox:Show, x380 y312 h243 w440, %UniqueIdentifier%
GuiControl, InputBox:Focus, UserInput
; Adress words by their index:
currentWordIndex := 0
IncorrectCount := 0
Retry := 0
GuiControl, InputBox:Focus, UserInput
GuiControl, InputBox:, UserInput,
Narration := "Type the word" . WordArray[currentWordIndex]
SayThis(Narration)
return
InputBoxGuiClose:
FileDelete, %A_ScriptDir%\SayThis.ahk
ExitApp
SayWordBtn:
{
SyCurrWord := WordArray[currentWordIndex]
SayThis(SyCurrWord)
}
Return
ShowWordBtn:
{
GuiControl, InputBox:, CorrectSpelling,% WordArray[currentWordIndex]
}
Return
CheckSpellingBtn:
Gui, InputBox:Submit, NoHide
If (WordArray[currentWordIndex] == UserInput)
{
hIcon := LoadPicture("imageres.dll", "w32 Icon233", _)
GuiControl, InputBox:, IconPic, % "HICON:" hIcon
GuiControl, InputBox:, SpellCheckMessage, That is correct
GuiControl, InputBox:, UserInput,
GuiControl, InputBox:, CorrectSpelling,
SayThis("That is correct")
If (Retry == 0){
WordsCorrectOnFirstTry += 1
}
WordCount += 1
currentWordIndex++ ; next word
Retry := 0
IncorrectCount := 0
; see how arrays make your life easy
If (currentWordIndex > WordArray.MaxIndex())
{
Summary_str =
(
You spelt %WordsCorrectOnFirstTry% correctly on your first try.
There were a total of %WordCount% words in this session and you had problems with %WordsWrongThisSession% of them.
You can find a list of the words you had the most difficulty with in %A_ScriptDir%\ProblematicWords\ProblematicWordsList.txt
)
MsgBox,, Summary, %Summary_str%
ExitApp
} Else{
GuiControl, InputBox:, UserInput,
Narration := "Type the word" . WordArray[currentWordIndex]
SayThis(Narration)
}
} else {
GuiControl, InputBox:, UserInput,
SayThis("Spelling is incorrect. Try again")
Retry := 1
GuiControl, InputBox:, SpellCheckMessage, Spelling is incorrect. Try again
hIcon := LoadPicture("imageres.dll", "w32 Icon230", _)
GuiControl, InputBox:, IconPic, % "HICON:" hIcon
IncorrectCount += 1
If (IncorrectCount >= 3){
CurrWrd := WordArray[currentWordIndex]
GuiControl, InputBox:, CorrectSpelling, % "Type the word " . WordArray[currentWordIndex]
FileCreateDir, %A_ScriptDir%\ProblematicWords
FileAppend, %CurrWrd%`r`n, %A_ScriptDir%\ProblematicWords\ProblematicWordsList.txt
}
If (IncorrectCount == 1){
WordsWrongThisSession += 1
}
}
GuiControl, InputBox:Focus, UserInput
return
GetWordsList(ByRef List, WindowTitle:="Waiting for Input") {
Global List_Edit
Gui, NewList:Add, Edit, vList_Edit x2 y2 w396 r4,
Gui, NewList:Add, Button, gList_OK x1 y63 w199 h30, &OK
Gui, NewList:Add, Button, gList_Cancel x200 y63 w199 h30, &Cancel
Gui, NewList:Show, h94 w400, %WindowTitle%
Goto, List_Wait
List_OK:
GuiControlGet, List_Edit
List_Cancel:
GuiEscape:
FileDelete, %A_ScriptDir%\SayThis.ahk
ReturnNow := True
List_Wait:
While (!ReturnNow)
Sleep, 100
Gui, NewList:Destroy
List := List_Edit
Return
}
SayThis(SomeString:="No text", Voice:="SAPI.SpVoice"){
SayThisFunctionText =
(
ComObjCreate("%Voice%").speak("%SomeString%")
Exitapp
)
FileDelete, %A_ScriptDir%\SayThis.ahk
FileAppend, %SayThisFunctionText%,%A_ScriptDir%\SayThis.ahk
RunWait, %A_AhkPath% "%A_ScriptDir%\SayThis.ahk"
FileDelete, %A_ScriptDir%\SayThis.ahk
Return
}
;SayThis(SomeString:="No text", Voice:="SAPI.SpVoice"){
; ComObjCreate(Voice).speak(SomeString)
; Return
;}
Esc::
ExitApp
FileDelete, %A_ScriptDir%\SayThis.ahk
Space::
{
Control, Check, , Button1, %UniqueIdentifier%
GuiControl, InputBox:Focus, UserInput
Return
}
I am unsure as to how to make this correction. I've tried putting a return but it did not work as expected could you show me an example and maybe elaborate a little.