我正在实现一个桌面应用程序,想要发送一个ALT+SPACE
的组合键,但我找不到任何方法来实现这个操作。
我正在自动处理以下任务:
- 在命令提示符中输入tracert命令
- 复制结果
- 将结果粘贴到记事本中
有人可以帮助我吗..?
试试这个
System.Windows.Forms.SendKeys.Send("% ");
编辑
使用SendKeys
有些“hacky”。相反,我建议使用Process类,如下所示:
public string GetTracert(string ip)
{
Process p = new Process();
p.StartInfo.FileName = "tracert";
p.StartInfo.Arguments = "123.123.123.123";
p.StartInfo.RedirectStandardOutput = true;
p.Start();
return p.StandardOutput.ReadToEnd();
}
请看一下
%{SPACE}
SendKeys.Send("% ");
// {SPACE} 不是有效的,所以使用常规的“ ”
这应该模拟 ALT + Space 键按下