[英]Simulate Control+v key press when creating a txt file
Hello everyone and thank you in advance. 大家好,谢谢。
I have copied a text and now I want to paste this text into a ".txt" what needs to be created automatically. 我已经复制了一个文本,现在我想将此文本粘贴到需要自动创建的“ .txt”中。 I know the paste simulation key is as follows:
我知道粘贴模拟的关键如下:
System.Windows.Forms.SendKeys.Send("^{v}");
On the other hand, the previous simulation key press should be included somehow within the following code (which creates a writes), but I am not sure how to do this... 另一方面,先前的模拟按键应该以某种方式包含在以下代码中(创建写操作),但是我不确定如何执行此操作...
public void writeTXT()
{
if (!File.Exists(path))
{
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine();
}
}
}
Any comments will be welcome! 任何意见将受到欢迎! Thanks a lot.
非常感谢。
You don't have to simulate keypresses. 您不必模拟按键。 You can access the clipboard directly:
您可以直接访问剪贴板:
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine(Clipboard.GetText());
}
You don't need to simulate a Ctrl+V. 您无需模拟Ctrl + V。
Use the Clipboard
class instead. 请改用
Clipboard
类。
You can find info in there : 您可以在此处找到信息:
https://docs.microsoft.com/fr-fr/dotnet/api/system.windows.clipboard?redirectedfrom=MSDN&view=netframework-4.7.2
https://docs.microsoft.com/fr-fr/dotnet/api/system.windows.clipboard?redirectedfrom=MSDN&view=netframework-4.7.2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.