如何在不使用 SetForegroundWindow()
激活目标窗口的情况下使用 SendWait()
将击键发送到窗口?
这是 MSDN 站点上的 SendWait 示例:http://msdn.microsoft.com/en-us/library/ms171548.aspx
最佳答案
参见 this thread .基本上给窗口一些句柄,你需要使用 p/invoke 并调用 PostMessage使用 WM_KEYDOWN
消息:
private const int VK_RETURN = 0x0D;
private const uint WM_KEYDOWN = 0x0100;
[DllImport("user32.dll", SetLastError = true)]
private static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
public void SendKeysToWindow(IntPtr hWnd)
{
PostMessage(hWnd, WM_KEYDOWN, new IntPtr(VK_RETURN), IntPtr.Zero);
}
这是 the list虚拟键。
关于c# - 如何在非事件窗口中用代码模拟键盘事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3593596/