【问题标题】:AutoHotKey Copy file to clipboard and pasteAutoHotKey 将文件复制到剪贴板并粘贴
【发布时间】:2017-10-14 12:06:53
【问题描述】:

我正在尝试使用 AutoHotKey 来自动化我的一些工作。与客户对应时,我有一个我使用的模板。我创建了模板并将其复制到剪贴板并使用 AutoHotKey 脚本将其保存到文件中 - 这部分工作正常。我现在想保存剪贴板中的任何内容,加载预先保存的文件,将其粘贴到我的 Outlook 消息窗口中,然后将保存的剪贴板恢复到剪贴板。我已经尝试了几种方法但没有成功 - 通常,复制到 Outlook 的内容是剪贴板中最初的内容。以下是我尝试过的脚本:

^F5::
  ClipSaved := ClipboardAll ; Save the entire clipboard to ClipSaved (Not just text)
  Clipboard =          ; Clear the clipboard
  FileRead, Clipboard, *c <fullpath to saved file like c:\dir\file.clip>
  MyErr = %ErrorLevel%
  if MyErr >= 1
  {
      MsgBox, Unable to read case_format.clip!
  }
  ClipWait, 5
  SendInput, ^v
  Clipboard := ClipSaved        ; Restore the clipboard we saved
  ClipSaved =                   ; Free the memory in case the clipboard was very large
Return

我也尝试过使用 WinClipApi,但它也不起作用。它没有复制任何内容,我最终会从 Windows 发出“哔”声:

^F5::
    WinClip.Snap( ClipSaved )
    WinClip.Clear()
    WinClip.Load( <full path to file like "c:\dir\file.clip"> )
    ClipWait,5,
    WinClip.Paste()
    WinClip.Restore( ClipSaved )
Return

我尝试过混合和匹配片段(例如在 WinClip 示例中使用 FileRead AHK 命令,用 'SendInput, ^v' 代替 WinClip.Paste() 等等),但似乎没有任何效果。有什么建议吗?

【问题讨论】:

  • 你想要Clipboard := ClipSaved,而不是Clipboard = ClipSaved

标签: load clipboard autohotkey paste


【解决方案1】:

您可能在 windows 完成处理之前销毁剪贴板 ctrl+v

在修改剪贴板之前等待窗口完成粘贴

SendInput, ^v
Sleep 2000                   ; Wait 2s for Windows to finish with clipboard
Clipboard := ClipSaved 

延迟的长度取决于您粘贴的内容。粘贴 100mb 的图像需要比几行文本更长的延迟

如果您的剪贴板包含文本以外的内容,请考虑使用 clipwait 的第二个参数:

ClipWait, 2, 1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-08
    • 1970-01-01
    相关资源
    最近更新 更多