【问题标题】:Cycle through synonyms of a selected word in AHK循环浏览 AHK 中所选单词的同义词
【发布时间】:2018-11-23 14:55:34
【问题描述】:

这是我想做的:

假设我在任意文本编辑器中有一句话:

蒂姆是个快乐的人。

如果我的光标正好放在单词的末尾 - e. G。 “happy”,然后我按下某个热键,脚本应该查看是否有包含单词“happy”的同义词池,如果有,替换它按列表中的下一个同义词。

因此您可以通过反复按下热键来循环浏览所有同义词。

同义词列表应该在脚本中,例如:

(
happy
cheerful
jolly
merry
lively
)

我发现this post 做了类似的事情。 (在那里,一个特定的词总是被随机的同义词替换)

问题:

  • 是否有脚本已经这样做了?
  • 如果不是 - 你会怎么做?

(我还应该提到我对 AHK 很陌生。)

【问题讨论】:

    标签: windows automation autohotkey


    【解决方案1】:

    我会使用这样的东西:

    #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
    

    【讨论】:

    • 菜单的想法更好,非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2013-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-24
    相关资源
    最近更新 更多