我需要找到键盘按键的自动化ID。如何通过UI自动化向应用程序发送按键击?我需要自动化页面向上和向下键的功能。最佳方法是什么?
编辑: 在我的应用程序中,以下是流程。假设最终用户打开具有5个页面的MS Word文档,并按Page Up和Page Down按钮在这些页面之间移动。我想使用C#自动化此场景。目前我已经使用了UIAutomationClient.dll和UIAutomationTypes.dll。我能使用它们吗?
我需要找到键盘按键的自动化ID。如何通过UI自动化向应用程序发送按键击?我需要自动化页面向上和向下键的功能。最佳方法是什么?
编辑: 在我的应用程序中,以下是流程。假设最终用户打开具有5个页面的MS Word文档,并按Page Up和Page Down按钮在这些页面之间移动。我想使用C#自动化此场景。目前我已经使用了UIAutomationClient.dll和UIAutomationTypes.dll。我能使用它们吗?
自动发送各种按键的一个很好的方式是使用AutoIt自动化和脚本语言。可以做很多事情,特别是向上翻页和向下翻页。
我建议使用autoit编写一个exe文件,并将其连接到需要发送按键的程序中。
SendWait("C")
。例如:
// Get a handle to an application window.
[DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
// Activate an application window.
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
// Send a series of key presses to the Calculator application.
private void button1_Click(object sender, EventArgs e)
{
// Get a handle to the Calculator application. The window class
// and window name were obtained using the Spy++ tool.
IntPtr calculatorHandle = FindWindow("CalcFrame","Calculator");
// Verify that Calculator is a running process.
if (calculatorHandle == IntPtr.Zero)
{
MessageBox.Show("Calculator is not running.");
return;
}
// Make Calculator the foreground application and send it
// a set of calculations.
SetForegroundWindow(calculatorHandle);
SendKeys.SendWait("111");
SendKeys.SendWait("*");
SendKeys.SendWait("11");
SendKeys.SendWait("=");
}
请参阅如何在代码中模拟鼠标和键盘事件>“向不同应用程序发送按键”。
我想你想要向一个没有源代码的应用程序发送按键。
我无法直接告诉你如何在C#中完成它。
但是你可以使用AutoIt轻松地完成它;它有一个DLL,你可以在C#中引用它来完成你需要的操作。
使用Windows表单并使用此列表与发送键
https://www.autoitscript.com/autoit3/docs/appendix/SendKeys.htm
我相当确定他只是要求他的SendKey.Send("{}");中键的值
System.Diagnostics.Process.Start("osk.exe");
并使用鼠标输入点击页面上下按钮