如何解决如何使用inputsimulator将按键从Winform发送到另一个应用程序?
我尝试发送一条消息,然后ctrl + ent进入chrome。 问题是几乎放弃后,它发送了ctrl + enter一次。 邮件已复制,粘贴在chrome中,但ctrl + enter命令不会发送到chrome。
这是我的代码的一部分: 顺便说一句,KeystrokeSimulation看起来像这样:
public void KeystrokeSimulation()
{
var inputSim = new InputSimulator();
inputSim.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
inputSim.Keyboard.KeyDown(VirtualKeyCode.RETURN);
inputSim.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
inputSim.Keyboard.KeyUp(VirtualKeyCode.RETURN);
}
private void button3_Click(object sender,EventArgs e)
{
int mousex = Cursor.Position.X;
int mousey = Cursor.Position.Y;
try
{
if (string.IsNullOrEmpty(textBox7.Text) && string.IsNullOrEmpty(textBox8.Text)
|| string.IsNullOrEmpty(textBox7.Text) || string.IsNullOrEmpty(textBox8.Text))
{
if (string.IsNullOrEmpty(button3.Text))
{
MessageBox.Show("Please select a message from the dropBox!");
}
else
{
Clipboard.SetText(button3.Text.ToString());
if (string.IsNullOrEmpty(textBox7.Text) && string.IsNullOrEmpty(textBox8.Text)
|| string.IsNullOrEmpty(textBox7.Text) || string.IsNullOrEmpty(textBox8.Text))
{
SendKeys.Send("^{v}");
IDataObject iData = Clipboard.GetDataObject();
textBox1.Text = (String)iData.GetData(DataFormats.Text);
}
else
{
DoMouseClick();
SendKeys.Send("^{v}");
IDataObject iData = Clipboard.GetDataObject();
textBox1.Text = (String)iData.GetData(DataFormats.Text);
}
}
}
else
{
int x = Int32.Parse(textBox7.Text);
int y = Int32.Parse(textBox8.Text);
Clipboard.SetText(button3.Text.ToString());
if (checkBox1.Checked == true)
{
Cursor.Position = new Point(pmousex,pmousey);
}
else
{
System.Windows.Forms.Cursor.Position = new Point(x,y);
}
DoMouseClick();
SendKeys.Send("^{v}");
KeystrokeSimulation();
System.Windows.Forms.Cursor.Position = new Point(mousex,mousey);
IDataObject iData = Clipboard.GetDataObject();
textBox1.Text = (String)iData.GetData(DataFormats.Text);
}
}
catch
{
//do nothing
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。