Created
January 28, 2021 02:27
-
-
Save nhoriguchi/bef17bd97642f65e19b17a2ba2a85442 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Kindle for PC を開いた状態で、現在開いているページから $pages 分連続でスクリーンショットを取ります。 | |
# スクリーンショットに含めたい範囲はディスプレイのサイズに依るので適宜 $xstart, $ystart, $xend, $yend を調節します。 | |
# 取得したスクリーンショットは $outfolder に保存されます。 | |
$pages = 3 | |
$Application = "Kindle" | |
$xstart = 1064 | |
$ystart = 2 | |
$xend = 2774 | |
$yend = 2160 | |
$outfolder = "Z:\tmp" | |
function Show-Process($Process, [Switch]$Maximize) | |
{ | |
$sig = ' | |
[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); | |
[DllImport("user32.dll")] public static extern int SetForegroundWindow(IntPtr hwnd); | |
' | |
if ($Maximize) { $Mode = 3 } else { $Mode = 4 } | |
$type = Add-Type -MemberDefinition $sig -Name WindowAPI -PassThru | |
$hwnd = $process.MainWindowHandle | |
$null = $type::ShowWindowAsync($hwnd, $Mode) | |
$null = $type::SetForegroundWindow($hwnd) | |
} | |
[Reflection.Assembly]::LoadWithPartialName("System.Drawing") | |
function screenshot([Drawing.Rectangle]$bounds, $path) { | |
$bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height | |
$graphics = [Drawing.Graphics]::FromImage($bmp) | |
$graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size) | |
$bmp.Save($path) | |
$graphics.Dispose() | |
$bmp.Dispose() | |
} | |
$ErrorActionPreference = "Stop" | |
$AppTime = Get-Process $Application | select id, starttime | |
If ($AppTime[0].starttime -gt $AppTime[1].starttime) { | |
$AppPID = $AppTime[0].id | |
} else { | |
$AppPID = $AppTime[1].id | |
} | |
Show-Process -Process (Get-Process -ID $AppPID) -Maximize | |
Start-Sleep -milliseconds 200 | |
$bounds = [Drawing.Rectangle]::FromLTRB($xstart, $ystart, $xend, $yend) | |
$wshell = New-Object -ComObject wscript.shell; | |
$wshell.AppActivate($AppPID) | |
For ($i=1; $i -le $pages; $i++) { | |
$tmp = $outfolder + "\" + $i + ".png" | |
screenshot $bounds $tmp | |
$wshell.SendKeys('{PGDN}') | |
Start-Sleep -milliseconds 200 | |
} | |
Start-Sleep -s 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment