[英]Powershell Chrome Zoom
我在PS1上使用以下代碼。 如何更改已打開的Chrome窗口的縮放比例。
start chrome --app="data:text/html,<html><body><script>window.moveTo(0,1080);window.resizeTo(960,540);window.location='<URL>;</script></body></html>"
據我所知,這不是一種編程方式,因此您的PowerShell腳本必須假裝為將Chrome窗口置於前台並按下所需鍵的用戶。
在下面的腳本中,我找到了與短語“ Google Chrome”匹配的窗口,將第一個窗口作為窗口,然后發送Ctrl + 0和兩個Ctrl + =按鍵,使其比默認值放大兩倍。
這些按鍵在腳本中表示為^0^=^=
。 同樣,您可以使用^0^-^-
進行縮小。 有關如何指定要發送到窗口的密鑰的更多信息,請參見https://msdn.microsoft.com/zh-cn/library/system.windows.forms.sendkeys(v=vs.110).aspx 。
$titleMatch = "Google Chrome"
$keys = "^0^=^="
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
# This C# fragment makes available a class that can set the foreground window
# since this is not a built-in feature in PowerShell.
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class SelectWindow {
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
}
"@
# Find the processes where the main window has a title that matches our query.
$processes = Get-Process | Where-Object { $_.MainWindowTitle -match $titleMatch }
if ($processes) {
# Get the main window handle of the first matching process.
$windowHandle = $processes[0].MainWindowHandle
# Bring that window to the front and send the keys to it.
[SelectWindow]::SetForegroundWindow($windowHandle) | Out-Null
[System.Windows.Forms.SendKeys]::SendWait($keys)
}
作為使用p \\ invoke的Don Cruickshank方法的替代方法,您還可以使用Microsoft.VisualBasic.Interaction
的AppActivate
方法使Chrome成為活動窗口。
Add-Type -AssemblyName Microsoft.VisualBasic
Add-Type -AssemblyName 'System.Windows.Forms'
$ID = (Start-Process chrome.exe -PassThru).id
Sleep 1
[Microsoft.VisualBasic.Interaction]::AppActivate([Int32]$ID)
[System.Windows.Forms.SendKeys]::SendWait("^0^=^=")
如果只需要臨時更改大小,則可以按Ctrl + / -進行縮放, 按Ctrl 0進行重置。
如果要在Javascript控制台中增加字體大小,則需要添加一些特定的大小,例如:
.source-code {
font-size: 16px !important;
font-family: monospace;
}
.console-prompt {
font-size: 16px !important;
font-family: monospace;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.