我一直在尝试创建一个可以并排打开两个边缘选项卡的脚本,但是我的脚本不起作用并且没有显示任何错误:
这是脚本
# On lance les deux instances de Edge
$edge1 = Start-Process -FilePath "msedge.exe" -PassThru
$edge2 = Start-Process -FilePath "msedge.exe" -PassThru
# Fonction pour attendre que la fenêtre soit ouverte
start-sleep 8
# On attend que les fenêtres soient ouvertes et chargées
$edge1Window = Wait-ForWindowOpen -Process $edge1
$edge2Window = Wait-ForWindowOpen -Process $edge2
$win1 = [System.Windows.Window]::new()
$win2 = [System.Windows.Window]::new()
# On redimensionne les fenêtres
if ($edge1Window -and $edge1Window.GetType().Name -eq "IntPtr") {
$source = [System.Windows.PresentationSource]::FromVisual([System.Windows.Interop.HwndSource]::FromHwnd($edge1Window))
$win1 = $source.RootVisual
$win1.Width = 300
$win1.Height = 800
$win1.WindowState = 'Normal'
}
if ($edge2Window -and $edge2Window.GetType().Name -eq "IntPtr") {
$source = [System.Windows.PresentationSource]::FromVisual([System.Windows.Interop.HwndSource]::FromHwnd($edge2Window))
$win2 = $source.RootVisual
$win2.Width = 800
$win2.Height = 600
$win2.WindowState = 'Normal'
}
目前两个边缘标签打开但它们没有移动并且并排放置。
我的电脑目前运行的是 Win10 21h2
答案1
我已经能够通过使用模拟 Windows 键的 Vscode 来解决这个问题。
下面是我使用的脚本,它将生成一个 EXE 文件,该 exe 文件可以用 powershell 命令触发:
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Public Module SendWinKey
Const KEYEVENTF_KEYDOWN As Integer = &H0
Const KEYEVENTF_KEYUP As Integer = &H2
Declare Sub keybd_event Lib "User32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As UInteger, ByVal dwExtraInfo As UInteger)
Public Sub Main()
keybd_event(CByte(Keys.LWin), 0, KEYEVENTF_KEYDOWN, 0) 'press the left Win key down
keybd_event(CByte(Keys.RIGHT), 0, KEYEVENTF_KEYDOWN, 0) 'press the right key down
keybd_event(CByte(Keys.RIGHT), 0, KEYEVENTF_KEYUP, 0) 'release the right key
keybd_event(CByte(Keys.LWin), 0, KEYEVENTF_KEYUP, 0) 'release the left Win key
End Sub
End Module