从 VB.net 中的键盘楔应用程序模拟复制粘贴
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30894207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Emulate copy-paste from Keyboard wedge application in VB.net
提问by Dominic
We have an application (written in VB 2005) that reads incoming characters on a virtual serial port (on which a Cognex barcode scanner is connected), validate the stream and send it to the focused object using the SendKeyscommand.
我们有一个应用程序(用 VB 2005 编写),它读取虚拟串行端口(连接 Cognex 条码扫描器)上的传入字符,验证流并使用SendKeys命令将其发送到聚焦对象。
It has worked perfectly for years, but now customers have new software and the SendKeysno longer works for a specific field in this software (it works everywhere else but this field). They did some tests and found out that, when they copy-paste text, it works using ctrl-c, ctrl-v.
它多年来一直运行良好,但现在客户有了新软件,并且SendKeys不再适用于该软件中的特定领域(它适用于除该领域之外的其他任何领域)。他们做了一些测试,发现当他们复制粘贴文本时,它可以使用 ctrl-c、ctrl-v。
My question is: how can I emulate those keystroke from our application?
我的问题是:如何从我们的应用程序中模拟这些击键?
回答by Sastreen
With SendKeys, the control key is ^. Then any additional keys can follow.
用SendKeys,控制键是^。然后可以跟随任何其他键。
So copy would be:
所以副本将是:
SendKeys.Send("^c")
And paste:
并粘贴:
SendKeys.Send("^v")
Instead of copying, you can just directly put it on the clipboard (like you suggested), like:
My.Computer.Clipboard.SetText("This is a test string.")
您可以直接将其放在剪贴板上(如您建议的那样),而不是复制,例如:
My.Computer.Clipboard.SetText("This is a test string.")

