通过发送信号向下滚动Web浏览器

我正在尝试将{PGDN}信号发送到网络浏览器。 这就是我打开网络浏览器的方式

curProcess = Process.Start("chrome.exe", "file:///D:/sample.htm"); 

我正试图获得该窗口的屏幕截图。 因为我没有尝试保存整页图像,所以想要向下滚动该页面并拍摄快照。我想发送“ 页面向下 ”会这样做。但仍然不知道该怎么做。 如何将密钥发送到curProcess

此代码为您提供了一个很好的解决方案!

  Process.Start("chrome.exe", "D:/sample.htm"); foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses()) { if (p.ProcessName == "chrome" && p.MainWindowTitle == "sample.htm - Google Chrome") { KeyHandle.SendKey(p.MainWindowHandle, Keys.PageDown); } } 

你也需要这门课

 class KeyHandle { private static Int32 WM_KEYDOWN = 0x100; private static Int32 WM_KEYUP = 0x101; [return: MarshalAs(UnmanagedType.Bool)] [DllImport("user32.dll", SetLastError = true)] static extern bool PostMessage(IntPtr hWnd, int Msg, System.Windows.Forms.Keys wParam, int lParam); public static void SendKey(IntPtr hWnd, System.Windows.Forms.Keys key) { PostMessage(hWnd, WM_KEYUP, key, 0); } } 

这是另一个使用sendKeys类的答案。

 Process.Start("chrome.exe", "D:/sample.htm"); foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses()) { if (p.ProcessName == "chrome" && p.MainWindowTitle == "sample.htm - Google Chrome" && p.MainWindowHandle != IntPtr.Zero) { KeyHandle.SetForeGround(p.MainWindowHandle); SendKeys.Send("{PGDN}"); } } 

和class级:

 class KeyHandle { [DllImport("user32.dll")] private static extern bool SetForegroundWindow(IntPtr hWnd); private static Int32 WM_KEYDOWN = 0x100; private static Int32 WM_KEYUP = 0x101; [return: MarshalAs(UnmanagedType.Bool)] [DllImport("user32.dll", SetLastError = true)] static extern bool PostMessage(IntPtr hWnd, int Msg, System.Windows.Forms.Keys wParam, int lParam); public static void SendKey(IntPtr hWnd, System.Windows.Forms.Keys key) { PostMessage(hWnd, WM_KEYUP, key, 0); } public static void SetForeGround(IntPtr hWnd) { SetForegroundWindow(hWnd); } }