一个简单的脚本可以方便修改鼠标滚轮方向
PowerShell 脚本
如果提示禁止运行该脚本,可以查看禁止运行脚本的解决方案
脚本如下:
# define a func to get mouse devices' info
function Get-MouseDevicesInfo {
[CmdletBinding()]
param()
$devices = Get-PnpDevice -Class Mouse
$result = @()
$id = 1
foreach ($device in $devices)
{
$status = $device.Status
if ($status -ne "OK") { continue }
$instanceId = (Get-PnpDeviceProperty -InstanceId $device.InstanceId -KeyName "DEVPKEY_Device_InstanceId").Data
# 这几项如果暂时不需要,可以不请求,提升性能
# $hardwareIds = (Get-PnpDeviceProperty -InstanceId $device.InstanceId -KeyName "DEVPKEY_Device_HardwareIds").Data -join ", "
# $manufacturer = (Get-PnpDeviceProperty -InstanceId $device.InstanceId -KeyName "DEVPKEY_Device_Manufacturer").Data
# $deviceDesc = (Get-PnpDeviceProperty -InstanceId $device.InstanceId -KeyName "DEVPKEY_Device_DeviceDesc").Data
$deviceParamKeyPath = "HKLM:\SYSTEM\CurrentControlSet\Enum\" + $instanceId + "\Device Parameters"
try
{
$flipFlopWheel = Get-ItemPropertyValue -Path $deviceParamKeyPath -Name "FlipFlopWheel" -ErrorAction Stop
}
catch
{
$flipFlopWheel = "Not Found"
}
$result += [PSCustomObject]@{
Id = $id++
Name = $device.Name
FlipFlopWheel = $flipFlopWheel
InstanceId = $instanceId
}
}
return $result
}
# define a func to modify FlipFlopWheel for device
function Set-FlipFlopWheel
{
param (
[string]$name, # Only for print name, not other functional usage
[string]$instanceId,
[int]$value
)
if ($value -ne 0 -and $value -ne 1)
{
Write-Output "Invalid value for FlipFlopWheel: $value. Please specify 0 or 1."
return
}
$deviceParamKeyPath = "HKLM:\SYSTEM\CurrentControlSet\Enum\" + $instanceId + "\Device Parameters"
try
{
Set-ItemProperty -Path $deviceParamKeyPath -Name "FlipFlopWheel" -Value $value -ErrorAction Stop
$newFlipFlopValue = Get-ItemPropertyValue -Path $deviceParamKeyPath -Name "FlipFlopWheel" -ErrorAction Stop
Write-Output "device $( $name )'s FlipFlopWheel value has been modified to $newFlipFlopValue."
}
catch
{
Write-Output "try to modify device $( $name )'s FlipFlopWheel value err: $_"
}
}
while ($true)
{
Write-Output "Scanning devices..."
$result = Get-MouseDevicesInfo
# print the device info to screen
$result | Format-Table -AutoSize
if ($result.Count -eq 0)
{
$userInput = Read-Host "No active HID-compliant mouse devices found. R to refresh or any to quit"
if ($userInput -in @("R", "r"))
{
continue
}
break
}
$selectedId = Read-Host "Please input id to modify (or Q to quit, or R to refresh)"
if ($selectedId -in @("Q", "q"))
{
break
}
if ($selectedId -in @("R", "r"))
{
continue
}
$selectedDevice = $result | Where-Object { $_.Id -eq [int]$selectedId }
if ($selectedDevice)
{
$target = 1
if ($selectedDevice.FlipFlopWheel -eq 1)
{
$target = 0
}
$userInput = Read-Host "Do you want to modify Id-($selectedId)'s FlipFlopWheel to $target ? (Y/N)"
if ($userInput -eq "Y" -or $userInput -eq "y")
{
Set-FlipFlopWheel -name $selectedDevice.Name -instanceId $selectedDevice.InstanceId -value $target
}
}
else
{
Write-Output "illegal device id."
}
Write-Output ""
$continueInput = Read-Host "Press Enter Q to quit or any to continue"
if ($continueInput -in @("Q","q"))
{
break
}
}
pause
执行完成之后,需要重新插拔鼠标