如何自动粘贴剪贴板数据? [英] How do I auto paste clipboard data?

查看:117
本文介绍了如何自动粘贴剪贴板数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要自动粘贴剪贴板数据,所以我尝试



SendKeys.Send(^ V);



但它不适用于文件下拉列表(它只能粘贴文本数据)



所以我如何以编程方式模拟Control + v按钮。



我尝试过:



SendKeys.Send(^ V );





但它不适用于文件下拉列表(它只能粘贴文本数据)

I need to paste clipboard data automatically and so i try

SendKeys.Send("^V");

But it wont work for file drop list (it can paste text data only)

So how i can simulate Control + v button programmatically.

What I have tried:

SendKeys.Send("^V");


But it wont work for file drop list (it can paste text data only)

推荐答案

在C#中,剪贴板是一个名为clipboard的标准类,这并不奇怪。它几乎可以在任何地方访问。



获取列表的伪代码是

In C# the clipboard is a standard class called clipboard not surprisingly. It is pretty much accessible anywhere.

The pseudocode to get the list is
if (Clipboard.ContainsFileDropList())
{
   ReturnList = Clipboard.GetFileDropList()

   // Do whatever you want with list now .. paste them wherever.
}



拦截你最想要WM_PASTE的消息,并将列表条目粘贴到你想要的地方。


Intercept whatever message you want WM_PASTE most likely and paste the list entries where you want too.


试试SendKeys.Send( ^ v);使用小写v



然后使用以下代码。



try SendKeys.Send("^v"); with a lower case v

and then use the following code.

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
      if (keyData == (Keys.Control | Keys.V))
      {
         var someData = Clipboard.GetFileDropList();
         //do something with the data
         return true;
      }
      else
      {
         return base.ProcessCmdKey(ref msg, keyData);
      }
}


这篇关于如何自动粘贴剪贴板数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆