53 lines
1.4 KiB
PowerShell
53 lines
1.4 KiB
PowerShell
Add-Type -TypeDefinition @"
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
public class MouseInput {
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct MOUSEINPUT {
|
|
public int dx;
|
|
public int dy;
|
|
public uint mouseData;
|
|
public uint dwFlags;
|
|
public uint time;
|
|
public IntPtr dwExtraInfo;
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct INPUT {
|
|
public uint type;
|
|
public MOUSEINPUT mi;
|
|
}
|
|
|
|
[DllImport("user32.dll")]
|
|
public static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
|
|
|
|
public const uint INPUT_MOUSE = 0;
|
|
public const uint MOUSEEVENTF_MOVE = 0x0001;
|
|
}
|
|
"@
|
|
|
|
Add-Type -AssemblyName System.Windows.Forms
|
|
|
|
$pos = [System.Windows.Forms.Cursor]::Position
|
|
Write-Host "当前位置: X=$($pos.X), Y=$($pos.Y)"
|
|
|
|
$input = New-Object MouseInput+INPUT
|
|
$input.type = [MouseInput]::INPUT_MOUSE
|
|
$input.mi.dx = 1
|
|
$input.mi.dy = 0
|
|
$input.mi.dwFlags = [MouseInput]::MOUSEEVENTF_MOVE
|
|
$input.mi.time = 0
|
|
$input.mi.dwExtraInfo = [IntPtr]::Zero
|
|
|
|
$size = [Runtime.InteropServices.Marshal]::SizeOf($input)
|
|
$result = [MouseInput]::SendInput(1, @($input), $size)
|
|
Write-Host "SendInput 返回: $result (右移1像素)"
|
|
|
|
Start-Sleep -Seconds 2
|
|
|
|
$input.mi.dx = -1
|
|
$result = [MouseInput]::SendInput(1, @($input), $size)
|
|
Write-Host "SendInput 返回: $result (移回原位)"
|
|
Write-Host "测试完成"
|