我会使用这样的东西:
#NoEnv
#SingleInstance Force
synonyms=
(
happy,cheerful,jolly,merry,lively
unhappy,sad,down,depressed
calm,quiet,peaceful,still
; ...
)
$F1::
synonyms_found := "" ; empty this variable (erase its content)
Menu, Replace Synonym, Add
Menu, Replace Synonym, deleteAll ; empty this menu
ClipSaved := ClipboardAll ; save the entire clipboard to the variable ClipSaved
clipboard := "" ; empty the clipboard (start off empty to allow ClipWait to detect when the text has arrived)
Send ^+{Left} ; select the word left to cursor
Sleep, 50
Send ^c ; copy the selected word
ClipWait 0.5 ; wait 0.5 seconds for the clipboard to contain data
if (ErrorLevel) ; If ErrorLevel, clipwait found no data on the clipboard within 0.5 seconds
{
MsgBox, No word selected
clipboard := ClipSaved ; restore original clipboard
return ; don't go any further
}
; otherwise:
Loop, Parse, synonyms, `n,`r ; retrieve each line from the synonyms, one at a time
{
If InStr(A_LoopField, clipboard) ; if the retrieved line contains the word copied
{
synonyms_found .= A_LoopField . "," ; concatenate (join) the retrieved lines into a single variable
Loop, Parse, synonyms_found, `, ; retrieve each word from the retrieved lines
Menu, Replace Synonym, Add, %A_LoopField%, Replace_Synonym ; create a menu of the synonym words
}
}
If (synonyms_found != "") ; if this variable isn't empty
Menu, Replace Synonym, Show
else
MsgBox, No synonyms found for "%clipboard%"
Sleep, 300
clipboard := ClipSaved ; restore original clipboard
return
; select a menu item to replace the selected word:
Replace_Synonym:
SendInput, %A_ThisMenuItem%
return