循环插入和退出剪贴板

编程入门 行业动态 更新时间:2024-10-21 15:54:04
本文介绍了循环插入和退出剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用以下代码将文本复制到剪贴板。

I'm using the following code to copy text to Clipboard.

System.Windows.Forms.SendKeys.SendWait("^c");

然后我使用

Clipboard.GetText()

从剪贴板获取文本。它可以正常工作,但是当我循环使用剪贴板并收到应该用下一个复制的文本覆盖的内容时,它似乎延迟了。如果我把Thread.sleep放进去,那就可以了。我该如何快速地从剪贴板中快速复制并从剪贴板中获取正确的内容而没有延迟?

to get the text from Clipboard. It works fine, but it looks like it's delaying when I work with clipboard in a loop and I get content that should be overwritten with next copied text. If I put the Thread.sleep, it works fine. How could I fast copy and get the right content from Clipboard in a loop without delay?

推荐答案

您绝对无法更新剪贴板循环运行,并希望数据立即可用(您的应用可以访问)。您要发送击键的应用程序正在其自己的进程中运行,而Windows是多处理,多线程等。因此,您正在寻找要更新的剪贴板,而另一个应用程序尚未获得更新。 此外,由于系统上可能有其他程序正在运行,监视剪贴板中的更新(剪贴板查看器),因此当您尝试获取这些文件时,将与这些程序发生冲突。剪贴板中的数据。 我不知道您为什么要尝试做自己正在做的事情,但是您应该知道它不会一直工作。在某些情况下(但并非在所有情况下),您也许可以使它工作。除非这是您自己的教育用途,否则应该放弃这种方法。

You definitely can NOT update the clipboard in a loop and expect the data to be available (and accessible to your app) immediately. The application that you're sending the keystroke to is running in its own process, and windows is multi-processing, multi-threading, etc.. So you're looking for the clipboard to be updated, before the other app has gotten a chance to copy it. Furthermore, since there can be other programs running on the system, monitoring the clipboard for updates (clipboard viewers), you are going to be colliding with those programs when you attempt to get the data from the clipboard. I don't know why you're trying to do what you're doing, but you should be aware that it's not going to work all the time. You may be able to get it to work in some cases, but not all cases. Unless this is an educational exercise for your own use, you should abandon this approach.

并且请阅读以下主题的报价:

And please read this quote on the subject:

如果没有用户的明确指示,程序不得将数据从剪贴板中传输到我们的剪贴板中。 -Charles Petzold,Windows 3.1编程,Microsoft Press,1992

"Programs should not transfer data into our out of the clipboard without an explicit instruction from the user." — Charles Petzold, Programming Windows 3.1, Microsoft Press, 1992

更多推荐

循环插入和退出剪贴板

本文发布于:2023-11-03 15:20:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555434.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:剪贴板

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!