复制不相邻的单词并将它们连接在一起

问题描述 投票:0回答:1

正如标题所说,我想在任何应用程序(Web 浏览器、电子邮件、MS Word、编辑器、Evernote 等)中复制并加入任意数量(大部分)不相邻的单词。也就是说,我(鼠标)选择并复制击中

5
键的任何单词,同时按住
F4
(但实际上任何不会干扰其正常功能的热键和修饰符,并且用左手也可以轻松且同时触及).

这是我用我有限的 AHK 技能想出来的。剪贴板部分有效,但据我所知,

global
变量(因此不是单词连接)也不知道
F4 Down & 5
热键组合(没有
Down
或没有
& 5
,从技术上讲,不过):

global MyString := ""                    ; make string global to keep contents between {5}-key presses

~F4 Down & 5::                           ; copy any (non-adjacent) words with {5}-key as long as I hold down {F4}-key
    clipboard := ""
    Sleep 100
    Send ^c
    ClipWait, 1
    MyString := MyString Trim(clipboard) ; append lastly copied word to any words copied before (while holding down {F4})

~F4 Up::
    MsgBox, %MyString%                   ; show final string consisting of ALL copied words separated by a space
    MyString := ""                       ; reset string

Return

最终,我想将

%MyString%
作为一个长字符串复制到剪贴板,而不是将其显示在消息框中。我想我已经接近解决方案了。

你能解决吗?

autohotkey
1个回答
1
投票

您永远不会结束第一个热键的执行块,因此它的执行会渗透到下面的热键中,并且您的

MyString
每次都会重置。 此外,如果您有
down
/
up
热键对,则无需指定第一个
down
,仅指定
up

另外,没有必要让你的变量超级全局

固定脚本:

~F4 & 5::                         
    Clipboard := ""
    Sleep, 100
    Send, ^c
    ClipWait, 1
    MyString := MyString " " Trim(Clipboard) 
return

~F4 Up::
    MsgBox, % MyString                
    MyString := ""  
return

顺便说一句,脚本的想法非常酷。我自己可能会使用这样的东西。

© www.soinside.com 2019 - 2024. All rights reserved.