Git Product home page Git Product logo

get-printscreenwithpowershell's Introduction

💎powershellでスクリーンショットを取るやつ

💎スクリプト名 :Get-PrintScreen.ps1

実行するとディスプレイサイズを取得して全画面のスクリーンショットを取得する。
出力するフォルダは引数による(デフォルトはスクリプトが格納されている同フォルダ)
出力ファイル名はyyyyMMdd_HHmmssfff
出力形式は引数による(デフォルトはpng)

※注意事項

一応、文字のスケーリングを使用している場合とかでもスクリーンショットが取れるような感じになっている筈。

マルチディスプレイには対応してません。プライマリのモニタスクリーンショットを取る筈。 powrshell_ise.exeだとうまく実行できません。備考参照

💎基本的な使い方

Get-PrintScreen.ps1のショートカットを作成して、そのショートカットをデスクトップに置く

(ショートカットのショートカットキーが有効なのがデスクトップのみなので)

作成したショートカットファイルを下記に従って編集する。

💎リンク先

サンプル1

powershell.exe -WindowStyle Hidden -command "&{. .\Get-PrintScreen.ps1;Get-PrintScreen}"

引数を指定する場合は

サンプル2

powershell.exe -WindowStyle Hidden -command "&{. .\Get-PrintScreen.ps1;Get-PrintScreen -SleepTime 5}"

やっている事はpowershell.exeに引数を与えてスクリプトをドットソースで読み込んで関数Get-PrintScreenを実行している。

powershell.exeの引数

windowstyle引数で hidden を指定するのはすぐにウィンドウが閉じるように(これをやらないとスクリーンショット取得時にコンソールが映り込む)

▶WindowsStyle Hiddenを使わないで実行時の大きさを最小化にしても写り込まないかも。
最小化設定

command 引数でスクリプトブロックを利用してドットソースでps1ファイルの読み込みから関数の呼び出しを実行する。

"&{. .\Get-PrintScreen.ps1;Get-PrintScreen -SleepTime 5}"

💎作業フォルダ

スクリプトが格納されているフォルダ

💎ショートカットキー

お好きなやつ

💎使い方一例

▶リンク先にpowershell.exe -WindowStyle Hidden -command "&{. .\Get-PrintScreen.ps1;Get-PrintScreen}"
ショートカット一例

作業フォルダにスクリプトが格納されているフォルダ

ショートカットキーに使いたいショートカットキーを入力する

💎注意点

ショートカットはデスクトップに配置して下さい。 他の場所だとショートカットキーが有効になりません。

引数一覧

引数 説明 デフォルト値
-SleepTime [int] 指定秒まってからスクリーンショットの取得
-SaveDir スクリーンショット保存ディレクトリ Get-PrintScreen.ps1格納ディレクトリ
-isMsgBox [boolean]スクリーンショット取得後にOKのメッセージボックスを表示 $True
-isMouseCursor [boolean]スクリーンショットにマウスカーソルを含める $True
-Format 保存形式の指定(拡張子になります) png

備考

.NetのSystemInformationクラスのPrimaryMonitorSizeプロパティのメモ

powershell.exeで文字のスケーリングやRDP接続の環境下では該当プロパティではその物ズバリの画面サイズを返してくれない模様。 ただしpowershell_ise.exeで実行すると持ってこれてるみたい。

とりえあずスケーリングを利用している場合。 powershell.exeとpowershell_ise.exeで帰ってくる値が異なるのは知らないと嵌りそうなので注意。 (powershell_ise.exeでコーディングしてて、powershell.exeで実際に動かしたら挙動が違って少し嵌った!)

このスクリプトはpowershell.exeで画面サイズを取得してスケーリングの倍率を掛け算するロジックで画面サイズを取得していますが。

該当スクリプトをpowershell_ise.exeで動かすと、すでにスケーリングされた画像サイズにさらにスケーリングの倍率を掛け算して正しい画面サイズを取得できません。

exsample

スケーリング150%で2560x1440の時に

▶スケーリング150%
ディスプレイ設定

▶解像度2560x1440
ディスプレイ設定

[System.Windows.Forms.SystemInformation]::PrimaryMonitorSize

を実行すると

powershell.exe

IsEmpty Width Height
False 1707 960

powershell_ise.exe

IsEmpty Width Height
False 2560 1440

こんな感じで取得されるサイズが変わる。 多分、powershell_ise.exeだと色々とやっているのだろうかと思うが…… 直接の原因が何かまではまだ調査できていない。

get-printscreenwithpowershell's People

Contributors

senkousya avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

shortarrow

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.