32 lines
754 B
PowerShell
32 lines
754 B
PowerShell
|
|
param(
|
||
|
|
[Parameter(Mandatory=$true)]
|
||
|
|
[ValidateSet("up","down","mute","max")]
|
||
|
|
[string]$Action,
|
||
|
|
|
||
|
|
[int]$Times = 1
|
||
|
|
)
|
||
|
|
|
||
|
|
Add-Type -Name VolumeKey -Namespace Win32 -MemberDefinition @'
|
||
|
|
[DllImport("user32.dll")]
|
||
|
|
public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, System.UIntPtr dwExtraInfo);
|
||
|
|
'@
|
||
|
|
|
||
|
|
$KEY_UP = 0xAF
|
||
|
|
$KEY_DOWN = 0xAE
|
||
|
|
$KEY_MUTE = 0xAD
|
||
|
|
|
||
|
|
$vk = switch ($Action) {
|
||
|
|
"up" { $KEY_UP }
|
||
|
|
"down" { $KEY_DOWN }
|
||
|
|
"mute" { $KEY_MUTE }
|
||
|
|
"max" { $KEY_UP }
|
||
|
|
}
|
||
|
|
|
||
|
|
$count = if ($Action -eq "max") { 50 } else { $Times }
|
||
|
|
|
||
|
|
for ($i = 0; $i -lt $count; $i++) {
|
||
|
|
[Win32.VolumeKey]::keybd_event($vk, 0, 0, [UIntPtr]::Zero)
|
||
|
|
[Win32.VolumeKey]::keybd_event($vk, 0, 2, [UIntPtr]::Zero)
|
||
|
|
Start-Sleep -Milliseconds 25
|
||
|
|
}
|