34 lines
1.1 KiB
PowerShell
34 lines
1.1 KiB
PowerShell
|
|
param(
|
||
|
|
[Parameter(Mandatory=$true)]
|
||
|
|
[ValidateSet("left","right","middle","double","scroll_up","scroll_down")]
|
||
|
|
[string]$Action
|
||
|
|
)
|
||
|
|
|
||
|
|
Add-Type -Name MouseM -Namespace Win32 -MemberDefinition @'
|
||
|
|
[DllImport("user32.dll")]
|
||
|
|
public static extern void mouse_event(uint flags, int dx, int dy, int data, System.UIntPtr extra);
|
||
|
|
'@
|
||
|
|
|
||
|
|
$LEFTDOWN = 0x0002
|
||
|
|
$LEFTUP = 0x0004
|
||
|
|
$RIGHTDOWN = 0x0008
|
||
|
|
$RIGHTUP = 0x0010
|
||
|
|
$MIDDOWN = 0x0020
|
||
|
|
$MIDUP = 0x0040
|
||
|
|
$WHEEL = 0x0800
|
||
|
|
|
||
|
|
function Click([uint32]$down, [uint32]$up) {
|
||
|
|
[Win32.MouseM]::mouse_event($down, 0, 0, 0, [UIntPtr]::Zero)
|
||
|
|
Start-Sleep -Milliseconds 30
|
||
|
|
[Win32.MouseM]::mouse_event($up, 0, 0, 0, [UIntPtr]::Zero)
|
||
|
|
}
|
||
|
|
|
||
|
|
switch ($Action) {
|
||
|
|
"left" { Click $LEFTDOWN $LEFTUP }
|
||
|
|
"right" { Click $RIGHTDOWN $RIGHTUP }
|
||
|
|
"middle" { Click $MIDDOWN $MIDUP }
|
||
|
|
"double" { Click $LEFTDOWN $LEFTUP; Start-Sleep -Milliseconds 50; Click $LEFTDOWN $LEFTUP }
|
||
|
|
"scroll_up" { [Win32.MouseM]::mouse_event($WHEEL, 0, 0, 360, [UIntPtr]::Zero) }
|
||
|
|
"scroll_down" { [Win32.MouseM]::mouse_event($WHEEL, 0, 0, -360, [UIntPtr]::Zero) }
|
||
|
|
}
|