【问题标题】:Join lines automatically using autohotkey使用自动热键自动加入行
【发布时间】:2017-04-02 14:00:47
【问题描述】:

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

为了解决这个问题,我在记事本++中手动粘贴复制的文本>全选> 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.

在记事本++中手动加入后

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.

【问题讨论】:

标签: autohotkey


【解决方案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)
    }
}

【讨论】:

  • 它好像缺少一个 OnClipboardChange 函数。那是默认功能吗。也许我使用的是过时的 AHK
  • 在最新版本的 AHK 中,还有几个更早的版本。
【解决方案2】:

试试这个:

#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

【讨论】:

  • 我将“ahk_exe AcroRd32.exe”切换到“ahk_class AcrobatSDIWindow”并且它工作正常。唯一的事情是当我复制剪贴板时。它将 acrobat 的光标从 Text 切换到 Pan(Hand)。不知道为什么会这样。此外,如果我复制并移动到记事本太快(在剪贴板过程完成之前),连接线不会出现。我会看看我能弄清楚什么。谢谢!
  • 试试我编辑的答案。 @ahkcoder 的代码也适用于我。 This 是最新的 AHK 版本。
【解决方案3】:

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

之前:

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

【讨论】:

    猜你喜欢
    • 2012-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-20
    • 1970-01-01
    相关资源
    最近更新 更多