Skip to content

Instantly share code, notes, and snippets.

@yuki-tkd
Last active February 14, 2023 15:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuki-tkd/7a8b96db8201395d8c1af2b8fb2554bb to your computer and use it in GitHub Desktop.
Save yuki-tkd/7a8b96db8201395d8c1af2b8fb2554bb to your computer and use it in GitHub Desktop.
Capture a screenshot on Windows using AutoHotKey with shortcut keys similar to macOS.
Add-Type -AssemblyName System.Drawing, System.Windows.Forms
$jpegCodec = [Drawing.Imaging.ImageCodecInfo]::GetImageEncoders() | Where-Object { $_.FormatDescription -eq "JPEG" }
Start-Sleep -Milliseconds 200
[Windows.Forms.Sendkeys]::SendWait("{PrtSc}")
Start-Sleep -Milliseconds 200
$bitmap = [Windows.Forms.Clipboard]::GetImage()
$ep = New-Object Drawing.Imaging.EncoderParameters
$ep.Param[0] = New-Object Drawing.Imaging.EncoderParameter ([System.Drawing.Imaging.Encoder]::Quality, [long]100)
$now = Get-Date -format "yyyy-MM-dd_HH-mm-ss"
$path = "$env:USERPROFILE\Desktop\ScreenShot_${now}.jpg"
$bitmap.Save($path, $jpegCodec, $ep)
Add-Type -AssemblyName System.Drawing, System.Windows.Forms
$jpegCodec = [Drawing.Imaging.ImageCodecInfo]::GetImageEncoders() | Where-Object { $_.FormatDescription -eq "JPEG" }
Start-Sleep -Milliseconds 200
[Windows.Forms.Sendkeys]::SendWait("%{PrtSc}")
Start-Sleep -Milliseconds 200
$bitmap = [Windows.Forms.Clipboard]::GetImage()
$ep = New-Object Drawing.Imaging.EncoderParameters
$ep.Param[0] = New-Object Drawing.Imaging.EncoderParameter ([System.Drawing.Imaging.Encoder]::Quality, [long]100)
$now = Get-Date -format "yyyy-MM-dd_HH-mm-ss"
$path = "$env:USERPROFILE\Desktop\ScreenShot_${now}.jpg"
$bitmap.Save($path, $jpegCodec, $ep)
; ctrl + shift + 3 -> Capture screenshot of the screen
#if GetKeyState("LWin", "P")
Shift & 3::RunWait PowerShell.exe -ExecutionPolicy Unrestricted -File .\screenshot_all.ps1 ,, hide
; ctrl + shift + 4 -> Capture screenshot of an active window
#if GetKeyState("LWin", "P")
Shift & 4::RunWait PowerShell.exe -ExecutionPolicy Unrestricted -File .\screenshot_window.ps1 ,, hide
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment