【发布时间】:2016-03-25 03:58:00
【问题描述】:
这是我发现的一种方法,它将 IE ComObject 窗口置于前台并使用 SendKeys。
如何使用此方法发送一系列按键?
$ie = New-Object -ComObject InternetExplorer.Application
$ie.navigate("www.google.com")
do {sleep 1} until (-not ($ie.Busy))
Add-Type -AssemblyName System.Windows.Forms
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class StartActivateProgramClass {
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
}
"@
$hWnd = $ie.HWND
$ie.Visible = $true
[void] [StartActivateProgramClass]::SetForegroundWindow($hWnd)
[System.Windows.Forms.SendKeys]::SendWait("a 2")
【问题讨论】:
标签: shell powershell sendkeys