For some reason I
kept coming back to a post from this weekend about auto-correcting text on the Clipboard prior to pasting it, for which the answer was pretty much no. I kept thinking to myself,
"Of all the possibilities that have been realized in AHK how could something as simple as this have not been attempted?". After searching Scripts & Functions for about 15 minutes I could not find that any serious attempt had been made to do something even similar to that idea, so I figured it was worth a shot.
The intro GUI gives you the option of checking text that you have already saved to the Clipboard or opening a small text editor where you can type text and elect to have it spell checked once you are finished. The corrections are made in a loop that will produce a message box each time a potential correction is found, which will allow you to select whether you would like to keep the correction or dismiss it. You will also be given the option once the loop breaks to keep the corrections and continue or cancel.
This script was actually the easy part; the difficulty is the correction database. I basically had to slice and dice the
AutoCorrect script to extract the corrections into a workable format but the list is so massive that it's difficult to test and correct each entry in an effective manner. In other words, the corrections may be bug prone, but if people are willing to test the script out and notify me of potential corrections to the list I can at least fine tune it.
The script for the spell checker itself will be posted here but the text file is depends on to work will have to be downloaded; I have it hosted at autohotkey.net. Any suggestions on how I can improve the functionality of the script or make corrections to the text database are more than welcome:
Code:
;
; AutoHotkey Version: 1.0.48.03
; Language: English
; Platform: Win9x/NT
; Author: sinkfaze <constibooter@gmail.com>
;
; Script Function:
; This is a script that will allow you to spell check text that you have copied on the Clipboard, or, it will
; open a small editor where you can type text and elect to have it spell checked when you are finished.
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
Gui, Add, Text, x16 y10 w200 h20 +Center, Which would you like to do?
Gui, Add, Button, yp+20 wp hp gCheckClip, Run spell check on the Clipboard.
Gui, Add, Button, yp+25 wp hp gRunEdit, Open the Editor so I can write.
Gui, Show, AutoSize Center, AHK Spell Checker
Return
CheckClip:
Gui, Destroy
TestVar := Clipboard
Loop, read, SpellCheck.txt
{
IfInString, TestVar, % SubStr(A_LoopReadLine,1,InStr(A_LoopReadLine,"|")-1)
{
MsgBox, 68, AHK Spell Checker, % TestVar "`n`n" SubStr(A_LoopReadLine,1,InStr(A_LoopReadLine,"|")-1) " will be changed to " SubStr(A_LoopReadLine,InStr(A_LoopReadLine,"|")+1) "`n`nContinue with replacement?"
ifMsgBox, Yes
StringReplace, TestVar, TestVar, % SubStr(A_LoopReadLine,1,InStr(A_LoopReadLine,"|")-1), % SubStr(A_LoopReadLine,InStr(A_LoopReadLine,"|")+1), All
else
continue
}
}
MsgBox, 33, AHK Spell Checker, % TestVar "`n`nAre you sure you would like to replace the Clipboard's contents`nwith the above text?"
IfMsgBox, OK
{
Clipboard := TestVar
ClipWait
MsgBox, The text has been converted and saved to the Clipboard.
Reload
return
}
Else
{
Reload
Return
}
RunEdit:
Gui, Destroy
Gui, 2: Add, Text, x16 y10 w370 h20 +Center, Enter the text you would like to spell check.
Gui, 2: Add, Edit, x16 y30 w370 R16 , ; h220
Gui, 2: Add, Button, x236 y250 w70 h23 g2SpellCheck, Spell Check
Gui, 2: Add, Button, x316 y250 w70 h23 g2Cancel, Cancel
Gui, 2: Show, AutoSize Center, Spell Check Editor
Return
2SpellCheck:
ControlGetText, TestVar, Edit1, Spell Check Editor
Loop, read, SpellCheck.txt
{
IfInString, TestVar, % SubStr(A_LoopReadLine,1,InStr(A_LoopReadLine,"|")-1)
{
MsgBox, 68, AHK Spell Checker, % TestVar "`n`n" SubStr(A_LoopReadLine,1,InStr(A_LoopReadLine,"|")-1) " will be changed to " SubStr(A_LoopReadLine,InStr(A_LoopReadLine,"|")+1) "`n`nContinue with replacement?"
ifMsgBox, Yes
{
StringReplace, TestVar, TestVar, % SubStr(A_LoopReadLine,1,InStr(A_LoopReadLine,"|")-1), % SubStr(A_LoopReadLine,InStr(A_LoopReadLine,"|")+1), All
Continue
}
else
Continue
}
}
MsgBox, 33, AHK Spell Checker, % TestVar "`n`n Are you sure you would like to replace the Editor's contents`nwith the above text?"
IfMsgBox, OK
{
ControlSetText, Edit1, %TestVar%, Spell Check Editor
MsgBox, The text in the Editor has been converted.
Return
}
Else
Reload
GuiClose:
2Cancel:
2GuiClose:
ExitApp
Download SpellCheck.txt