Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

AutoCorrect script (a bit better) =)


  • Please log in to reply
8 replies to this topic
4DBoy
  • Members
  • 2 posts
  • Last active: Feb 16 2013 03:21 PM
  • Joined: 03 Feb 2013

Hello everyone =)

I recently downloaded the "AutoCorrect for AHK-L.ahk" which offers a huge list of hotstrings which help to reduce typos on the pc.

If you don't know the script you can check it out here: http://www.howtogeek...on-your-system/

 

What I changed is the function which makes the user able to add new hotstrings via a GUI.

This is what usually happens when the user wants to add a new typo correction to the script:

  1. the user selects the misspelled word
  2. presses the windows key + h (#h) which will show the GUI
  3. the user can correct the word and press OK in order to reload the script

the next step is what I added:

     4.  The selected (misspelled) word will be replaced by the corrected word

 

(it will also trim the misspelled word and automatically select the second edit field in the GUI)

 

So tiny changes but I think they are quite helpful because you don't have to correct twice and sort out the spaces manually.

Please let me know if you have suggestions or helpful ideas to make the script even better.

Here's the new source code(this is not the whole AutoCorrect script but the important one for this feature):

#NoEnv
#SingleInstance force

; send the corrected word on reload (will replace the selected word)
if(%0% > 1)
    Send, %2%

; a tiny GUI setup
Gui, Add, Edit, vfrom w300  ,%Hotstring%::
Gui, Add, Edit, vto  w300 ym0,%Hotstring%
Gui, Add, Button, Default, OK

#h::
	AutoTrim Off  
	ClipboardOld = %ClipboardAll%
	Clipboard =  
	Send ^c
	ClipWait 1
	if ErrorLevel  
		return
	StringReplace, Hotstring, Clipboard, ``, ````, All  
	StringReplace, Hotstring, Hotstring, `r`n, ``r, All
	StringReplace, Hotstring, Hotstring, `n, ``r, All
	StringReplace, Hotstring, Hotstring, %A_Tab%, ``t, All
	StringReplace, Hotstring, Hotstring, `;, ```;, All
	
	; trim the word (better imo)
	Hotstring :=  Trim(Hotstring)
	
	Clipboard = %ClipboardOld% 
	
	; setting the hotstrings in the GUI
	GuiControl,, to, %Hotstring%
	GuiControl,, from, %Hotstring%::
	
	; focus to the "to" gui
	GuiControl, Focus, to
	Gui, Show
	
	; send control + a in order toselecctthe text in the "to" gui (better imo)
	Send, ^a
return

; happens when pressing the OK button
ButtonOK:
    ; assembling the hotstring and save it to this file
    GuiControlGet, to
    GuiControlGet, from
    Hotstring := "::" from to
    FileAppend, `n%Hotstring%, %A_ScriptFullPath%  

    ; special reload statement with the word in the "to" gui
    Run, %A_ScriptFullPath% /restart %to%

    Sleep 200
    MsgBox, 4,, The hotstring just added appears to be improperly formatted.  Would you like to open the script for editing? Note that the bad hotstring is at the bottom of the script.
    IfMsgBox, Yes, Edit
return

 



michaelbeijer
  • Members
  • 16 posts
  • Last active: Jan 09 2015 09:26 AM
  • Joined: 13 Dec 2011

Very cool, thanks!

 

Michael



tov
  • Members
  • 2 posts
  • Last active: Dec 14 2014 05:59 PM
  • Joined: 17 Sep 2014

Thanks a lot for this script.

I did some adjustements as I was getting an error because the 'Run' command works only if the AHK is already installed on the system. I use the portable version. I also added an extra Edit box for hostrings options.

#NoEnv
#SingleInstance force

; a tiny GUI setup
Gui, Add, Text, x20 y50 w10 h20 +Center, :
Gui, Add, Edit, vopt x30 y50 w40 h20 +Center, 
Gui, Add, Text, x70 y50 w10 h20 +Center, :
Gui, Add, Edit, vfrom x90 y50 w300 h20, 
Gui, Add, Text, x400 y50 w10 h20 +Center, ::
Gui, Add, Edit, vto x420 y50 w300 h20, 
Gui, Add, Button, x270 y100 w80 h30 Default, OK
Gui, Add, Button, x390 y100 w80 h30, Cancel

#h::
    ; Get the selected text. The clipboard is used instead of "ControlGet Selected" as it works in 
;more editors and word processors, java apps, etc. Save the current clipboard contents to be restored later.

	AutoTrim Off   ; Retain any leading and trailing whitespace on the clipboard.
	ClipboardOld = %ClipboardAll%
	Clipboard =   ; Must start off blank for detection to work.
	Send ^c
	ClipWait 1 
	if ErrorLevel   ; ClipWait timed out.
		return
     ; Replace CRLF and/or LF with `n for use in a "send-raw" hotstring: The same is done for any other characters that might otherwise be a problem in raw mode:

	StringReplace, Hotstring, Clipboard, ``, ````, All   ; Do this replacement first to avoid interfering with the others below.
	StringReplace, Hotstring, Hotstring, `r`n, ``r, All ; Using `r works better than `n in MS Word, etc.
	StringReplace, Hotstring, Hotstring, `n, ``r, All
	StringReplace, Hotstring, Hotstring, %A_Tab%, ``t, All
	StringReplace, Hotstring, Hotstring, `;, ```;, All
	
	; trim the word (better imo)
	Hotstring :=  Trim(Hotstring)
	
	Clipboard = %ClipboardOld%  ; Restore previous contents of clipboard.
	
	; setting the hotstrings in the GUI
	GuiControl,, to, %Hotstring%
	GuiControl,, from, %Hotstring%
	
	; focus to the "to" gui
	GuiControl, Focus, to
	Gui, Show,, Add a correction or shortcut
	
	; send control + a in order to selecct the text in the "to" gui (better imo)
	Send, ^a
return

; happens when pressing the OK button 
ButtonOK:
    ; assembling the hotstring and save it to this file
    GuiControlGet, opt
    GuiControlGet, to
    GuiControlGet, from
    Hotstring := ":" opt ":" from "::" to
    FileAppend, `n%Hotstring%, %A_ScriptFullPath%  
    Gui, Show, Hide
    Send %to% ;replace the initial word with the corrected one 
    Reload

    Sleep 200 ; If successful, the reload will close this instance during the Sleep, so the line below willyt never be reached.
    MsgBox, 4,, The hotstring just added appears to be improperly formatted.  Would you like to open the script for editing? Note that the bad hotstring is at the bottom of the script.
    IfMsgBox, Yes, Edit
return

GuiEscape:
GuiClose:
ButtonCancel:
	Gui, Show, Hide
return




SirGalahad
  • Members
  • 2 posts
  • Last active: Sep 23 2014 12:31 AM
  • Joined: 21 Sep 2014

> tov

 

I get errors when I add your script.

 

I have the original AutoCorrect.ahk which works fine, but I don't know how to get yours working

 

I've tried inserting it in the original but In don't now where to insert it.

 

Any chance you could post the whole script?

 

Many thanks

 

TG 



SirGalahad
  • Members
  • 2 posts
  • Last active: Sep 23 2014 12:31 AM
  • Joined: 21 Sep 2014

> Toc

 

I fixed it by taking out the line:

 

Hotstring :=  Trim(Hotstring)

 

Works great - thanks very much

 

TG



tov
  • Members
  • 2 posts
  • Last active: Dec 14 2014 05:59 PM
  • Joined: 17 Sep 2014

The script posted above works with AHK v1.1.16.04 as such (no modifications needed).
To insert it in the autocorrect script I broke it into GUI initialization, hotkey code and GUI - subroutines. The autocorrect script is posted below, but note that I had to trim the code as it is too big to post it and I can't upload a file. The full script can be found at http://www.autohotke...AutoCorrect.ahk .

;------------------------------------------------------------------------------
; CHANGELOG:
; 
; Sep 13 2007: Added more misspellings.
;              Added fix for -ign -> -ing that ignores words like "sign".
;              Added word beginnings/endings sections to cover more options.
;              Added auto-accents section for words like fiancée, naïve, etc.
; Feb 28 2007: Added other common misspellings based on MS Word AutoCorrect.
;              Added optional auto-correction of 2 consecutive capital letters.
; Sep 24 2006: Initial release by Jim Biancolo (http://www.biancolo.com)
; 
; INTRODUCTION
; 
; This is an AutoHotKey script that implements AutoCorrect against several
; "Lists of common misspellings":
; 
; This does not replace a proper spellchecker such as in Firefox, Word, etc.
; It is usually better to have uncertain typos highlighted by a spellchecker
; than to "correct" them incorrectly so that they are no longer even caught by
; a spellchecker: it is not the job of an autocorrector to correct *all*
; misspellings, but only those which are very obviously incorrect.
; 
; From a suggestion by Tara Gibb, you can add your own corrections to any
; highlighted word by hitting Win+H. These will be added to a separate file,
; so that you can safely update this file without overwriting your changes.
; 
; Some entries have more than one possible resolution (achive->achieve/archive)
; or are clearly a matter of deliberate personal writing style (wanna, colour)
; 
; These have been placed at the end of this file and commented out, so you can
; easily edit and add them back in as you like, tailored to your preferences.
; 
; SOURCES
; 
; http://en.wikipedia.org/wiki/Wikipedia:Lists_of_common_misspellings
; http://en.wikipedia.org/wiki/Wikipedia:Typo
; Microsoft Office autocorrect list
; Script by jaco0646 http://www.autohotkey.com/forum/topic8057.html
; OpenOffice autocorrect list
; TextTrust press release
; User suggestions.
; 
; CONTENTS
; 
;   Settings
;   AUto-COrrect TWo COnsecutive CApitals (commented out by default)
;   Win+H code
;   Fix for -ign instead of -ing
;   Word endings
;   Word beginnings
;   Accented English words
;   Common Misspellings - the main list
;   Ambiguous entries - commented out
;------------------------------------------------------------------------------

;------------------------------------------------------------------------------
; Settings
;------------------------------------------------------------------------------
#NoEnv ; For security
#SingleInstance force

;------------------------------------------------------------------------------
; INITIALIZATION - GUI
;------------------------------------------------------------------------------
; a tiny GUI setup
Gui, Add, Text, x20 y50 w10 h20 +Center, :
Gui, Add, Edit, vopt x30 y50 w40 h20 +Center, 
Gui, Add, Text, x70 y50 w10 h20 +Center, :
Gui, Add, Edit, vfrom x90 y50 w300 h20, 
Gui, Add, Text, x400 y50 w10 h20 +Center, ::
Gui, Add, Edit, vto x420 y50 w300 h20, 
Gui, Add, Button, x270 y100 w80 h30 Default, OK
Gui, Add, Button, x390 y100 w80 h30, Cancel

;------------------------------------------------------------------------------
; AUto-COrrect TWo COnsecutive CApitals.
; Disabled by default to prevent unwanted corrections such as IfEqual->Ifequal.
; To enable it, remove the /*..*/ symbols around it.
; From Laszlo's script at http://www.autohotkey.com/forum/topic9689.html
;------------------------------------------------------------------------------
/*
; The first line of code below is the set of letters, digits, and/or symbols
; that are eligible for this type of correction.  Customize if you wish:
keys = abcdefghijklmnopqrstuvwxyz
Loop Parse, keys
    HotKey ~+%A_LoopField%, Hoty
Hoty:
    CapCount := SubStr(A_PriorHotKey,2,1)="+" && A_TimeSincePriorHotkey<999 ? CapCount+1 : 1
    if CapCount = 2
        SendInput % "{BS}" . SubStr(A_ThisHotKey,3,1)
    else if CapCount = 3
        SendInput % "{Left}{BS}+" . SubStr(A_PriorHotKey,3,1) . "{Right}"
Return
*/


;------------------------------------------------------------------------------
; Win+H to enter misspelling correction.  It will be added to this script.
;------------------------------------------------------------------------------
#h::
    ; Get the selected text. The clipboard is used instead of "ControlGet Selected" as it works in 
;more editors and word processors, java apps, etc. Save the current clipboard contents to be restored later.

	AutoTrim Off   ; Retain any leading and trailing whitespace on the clipboard.
	ClipboardOld = %ClipboardAll%
	Clipboard =   ; Must start off blank for detection to work.
	Send ^c
	ClipWait 1 
	if ErrorLevel   ; ClipWait timed out.
		return
     ; Replace CRLF and/or LF with `n for use in a "send-raw" hotstring: The same is done for any other characters that might otherwise be a problem in raw mode:

	StringReplace, Hotstring, Clipboard, ``, ````, All   ; Do this replacement first to avoid interfering with the others below.
	StringReplace, Hotstring, Hotstring, `r`n, ``r, All ; Using `r works better than `n in MS Word, etc.
	StringReplace, Hotstring, Hotstring, `n, ``r, All
	StringReplace, Hotstring, Hotstring, %A_Tab%, ``t, All
	StringReplace, Hotstring, Hotstring, `;, ```;, All
	
	; trim the word (better imo)
	Hotstring :=  Trim(Hotstring)
	
	Clipboard = %ClipboardOld%  ; Restore previous contents of clipboard.
	
	; setting the hotstrings in the GUI
	GuiControl,, to, %Hotstring%
	GuiControl,, from, %Hotstring%
	
	; focus to the "to" gui
	GuiControl, Focus, to
	Gui, Show,, Add a correction or shortcut
	
	; send control + a in order to selecct the text in the "to" gui (better imo)
	Send, ^a
return


#Hotstring R  ; Set the default to be "raw mode" (might not actually be relied upon by anything yet).


;------------------------------------------------------------------------------
; Fix for -ign instead of -ing.
; Words to exclude: (could probably do this by return without rewrite)
; From: http://www.morewords.com/e nds-with/gn/
;------------------------------------------------------------------------------
#Hotstring B0  ; Turns off automatic backspacing for the following hotstrings.
::align::
::antiforeign::
::arraign::
::assign::



;
;TRIMMED CODE
;


::august::August
::september::September
::october::October
::november::November
::december::December

;-------------------------------------------------------------------------------
;  GUI subroutines
;-------------------------------------------------------------------------------

; happens when pressing the OK button 
ButtonOK:
    ; assembling the hotstring and save it to this file
    GuiControlGet, opt
    GuiControlGet, to
    GuiControlGet, from
    Hotstring := ":" opt ":" from "::" to
    FileAppend, `n%Hotstring%, %A_ScriptFullPath%  
    Gui, Show, Hide
    Send %to% ;replace the initial word with the corrected one 
    Reload

    Sleep 200 ; If successful, the reload will close this instance during the Sleep, so the line below willyt never be reached.
    MsgBox, 4,, The hotstring just added appears to be improperly formatted.  Would you like to open the script for editing? Note that the bad hotstring is at the bottom of the script.
    IfMsgBox, Yes, Edit
return

GuiEscape:
GuiClose:
ButtonCancel:
	Gui, Show, Hide
return

;-------------------------------------------------------------------------------
; Anything below this point was added to the script by the user via the Win+H hotkey.
;-------------------------------------------------------------------------------


dysert
  • Members
  • 2 posts
  • Last active: Jun 20 2016 01:58 PM
  • Joined: 28 May 2014

I hope this is the right place to post this (and that someone's listening)... I have the AutoCorrect.ahk script and love it. There's only one problem. I work with a database that has tables and fields with names like: tblCampaign, CampaignID, CampaignMPDataID, xCampaignLCV, et al. The problem is that sometimes the string "campaign" gets changed to "campaing". It doesn't happen all the time, but for certain permutations of letters that contain the string "campaign". What can I do to stop AutoCorrect from ever changing the string "campaign" (found anywhere as part of a larger string) into "campaing"? Thanks!



space
  • Members
  • 520 posts
  • Last active:
  • Joined: 12 Aug 2014
Check your hotstrings by opening the script. Do you have a campaign hotstring with the ? parameter perhaps you have something like :?:campaign::campaing or you've added an incorrect hotstring campaign -> campaing.

Skrell
  • Members
  • 384 posts
  • Last active: Jul 07 2016 05:03 PM
  • Joined: 23 Aug 2011

I don't understand this at all....HOW do we integrate 4dboy's new code with the original autocorrect script posted by tov ?