使用autohotkey自动加入行

时间:2017-04-02 14:00:47

标签: autohotkey

当文本被复制到剪贴板并粘贴到Word中时,Adobe Acrobat中的长段会导致换行符。

为了解决这个问题,我手动将复制的文本粘贴到Notepad ++>全选> ctrl + J(连接线)>全选>复制......然后将其粘贴到我的Word文档中。

我想使用autohotkey自动化这个连接线,因为我需要通过大量文档。我似乎无法在autohotkey脚本中直接处理这个问题。

实施例。

Data structures with labeled axes supporting automatic or explicit data alignment.
This prevents common errors resulting from misaligned data and working with
differently-indexed data coming from different sources.

手动加入Notepad ++后

Data structures with labeled axes supporting automatic or explicit data alignment. This prevents common errors resulting from misaligned data and working with differently-indexed data coming from different sources.

3 个答案:

答案 0 :(得分:1)

试试这个:

#Persistent
return

    OnClipboardChange:
If WinActive("ahk_exe AcroRd32.exe")
{
    clipboard =
    Send, {Ctrl down}c{Ctrl up}{Esc}
        ClipWait
    clip := RegExReplace(clipboard, "(\S.*?)\R(.*?\S)", "$1 $2") ; strip line breaks and replace them with spaces
    clipboard = %clip%  
    StringReplace clipboard, clipboard, % "  ", % " ", A         ; replace double spaces with single spaces 
        ClipWait
    ControlClick, x0 y0, A
}
return

修改

或者这个:

#Persistent
return

    OnClipboardChange:
If WinActive("ahk_class AcrobatSDIWindow")
{
    clipboard := ""
    Send, {Ctrl down}c{Ctrl up}{Esc}
        ClipWait
    clip := RegExReplace(clipboard, "(\S.*?)\R(.*?\S)", "$1 $2") ; strip line breaks and replace them with spaces
    StringReplace clip, clip, % "  ", % " ", A         ; replace double spaces with single spaces 
    clipboard := "" 
    clipboard = %clip% 
    ClipWait 2
    If !(ErrorLevel)
    {
        ToolTip, lines joined
        Sleep 500
        ToolTip
    }
}
return

答案 1 :(得分:1)

这有效:

#Persistent
OnClipboardChange("ClipChanged")
return

ClipChanged() {

    If (WinActive("ahk_exe AcroRd32.exe")) {
        For e, v in StrSplit(clipboard, "`n", "`r")
            x .= v " "
        clipboard := trim(x)
    }
}

答案 2 :(得分:0)

我考虑了以连字符结尾的行,添加了功能。

之前:

This occurs in elec-
tricity generation
systems.

之后:

This occurs in electricity generation systems.

代码:

#Persistent
return

    OnClipboardChange:
If WinActive("ahk_exe AcroRd32.exe")
{
    clipboard := ""
    Send, {Ctrl down}c{Ctrl up}{Esc}
        ClipWait
    clip := RegExReplace(clipboard, "(\S.*?)-\R(.*?\S)", "$1$2") ; strip line breaks with hyphen
    clip := RegExReplace(clip, "(\S.*?)\R(.*?\S)", "$1 $2") ; strip line breaks and replace them with spaces
    StringReplace clip, clip, % "  ", % " ", A ; replace double spaces with single spaces 
    clipboard := "" 
    clipboard = %clip% 
    ClipWait 2
    If !(ErrorLevel)
    {
        ToolTip, lines joined
        Sleep 500
        ToolTip
    }
}
return