powershell区域截图置顶显示

```powershell:screenshoot.ps1

Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;

public class Keyboard {
    [DllImport("user32.dll")]
    public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);
}
"@

Add-Type -AssemblyName System.Windows.Forms


Add-Type @"
  using System;
  using System.Runtime.InteropServices;

  public class User32 {
    [DllImport("user32.dll")]
    public static extern int GetAsyncKeyState(Int32 i);
  }
"@
$VK_SHIFT = 0x10
$VK_LWIN = 0x5B
$VK_S = 0x53

$global:positionDown = $null
$global:positionUp = $null

# 按下按键
[Keyboard]::keybd_event($VK_LWIN, 0, 0, 0)
[Keyboard]::keybd_event($VK_SHIFT, 0, 0, 0)
[Keyboard]::keybd_event($VK_S, 0, 0, 0)

# 释放按键
[Keyboard]::keybd_event($VK_S, 0, 2, 0)
[Keyboard]::keybd_event($VK_SHIFT, 0, 2, 0)
[Keyboard]::keybd_event($VK_LWIN, 0, 2, 0)

# # 创建一个新的快捷键对象
# $shortcut = New-Object System.Windows.Forms.Shortcut
# # 设置快捷键的键值
# $shortcut.ShortcutKeys = [System.Windows.Forms.Keys]::LWin + [System.Windows.Forms.Keys]::LShift + [System.Windows.Forms.Keys]::S
# # 运行快捷键
# $shortcut.Run()

[System.Windows.Forms.Clipboard]::Clear()

# 监视置顶区域位置(经常无效)
#while ($true) {
#  if ([User32]::GetAsyncKeyState(0x01) -ne 0) {
#    $global:positionDown = [System.Windows.Forms.Cursor]::Position
#    Write-Host "Mouse left button is down at position: X=$($position.X) Y=$($position.Y)"
#    while ([User32]::GetAsyncKeyState(0x01) -ne 0) {
#      Start-Sleep -Milliseconds 10
#    }
#    $global:positionUp = [System.Windows.Forms.Cursor]::Position
#    Write-Host "Mouse left button is up at position: X=$($position.X) Y=$($position.Y)"
#    break
#  }
#  Start-Sleep -Milliseconds 10
#}

# Start-Sleep -Milliseconds 100
# Add-Type -AssemblyName System.Windows.Forms

while ($true) {
    $image = [System.Windows.Forms.Clipboard]::GetImage()
    if ($null -ne $image) {
        break
    }
    Start-Sleep -Milliseconds 100
}

Add-Type -AssemblyName PresentationFramework

# 创建一个新的窗口
$window = New-Object System.Windows.Window
$window.Title = "Image Display"
$window.WindowStyle = 'None' # 无边框
$window.ResizeMode = 'NoResize' # 不可调整大小
$window.Topmost = $true # 置顶显示
# $window.BorderBrush = [System.Windows.Media.Brushes]::Red
# $window.BorderThickness = New-Object System.Windows.Thickness(1)

"X: $($global:positionDown.X) Y: $($global:positionDown.Y)"
# $window.Top = $global:positionDown.Y -lt $global:positionUp.Y ? $global:positionDown.Y : $global:positionUp.Y
# $window.Left = $global:positionDown.X -lt $global:positionUp.X ? $global:positionDown.X : $global:positionUp.X
#if ($global:positionDown.Y -lt $global:positionUp.Y) {
#    $window.Top = $global:positionDown.Y
#} else {
#    $window.Top = $global:positionUp.Y
#}
#if ($global:positionDown.X -lt $global:positionUp.X) {
#    $window.Left = $global:positionDown.X
#} else {
#    $window.Left = $global:positionUp.X
#}

# 创建一个Image控件并加载图片
# $image = New-Object System.Windows.Controls.Image
# $image.Source = New-Object System.Windows.Media.Imaging.BitmapImage -ArgumentList (New-Object System.Uri -ArgumentList (Resolve-Path "img.png"))

Add-Type -AssemblyName PresentationCore,PresentationFramework,System.Windows.Forms

$imageControl = New-Object System.Windows.Controls.Image

$clipboardImage = [System.Windows.Forms.Clipboard]::GetImage()
if ($clipboardImage -ne $null) {
    $stream = New-Object IO.MemoryStream
    $clipboardImage.Save($stream, [System.Drawing.Imaging.ImageFormat]::Png)
    $stream.Position = 0

    $bitmapImage = New-Object System.Windows.Media.Imaging.BitmapImage
    $bitmapImage.BeginInit()
    $bitmapImage.StreamSource = $stream
    $bitmapImage.EndInit()

    $imageControl.Source = $bitmapImage
} else {
    Write-Host "No image found on clipboard."
}


# 将Image控件添加到窗口中
$window.AddChild($imageControl)

# 获取图片的大小，并设置窗口的大小
$window.Width = $imageControl.Source.Width
$window.Height = $imageControl.Source.Height

# 添加鼠标双击事件
$window.Add_MouseDoubleClick({
    $window.Close()
})

# 添加鼠标按下事件
$window.Add_MouseLeftButtonDown({
    $window.DragMove()
})

# 显示窗口
$window.ShowDialog()



```