Skip to content

Instantly share code, notes, and snippets.

@rbleattler
Last active February 17, 2021 16:27
Show Gist options
  • Save rbleattler/da1e6d3e2426afee23103862a6b44105 to your computer and use it in GitHub Desktop.
Save rbleattler/da1e6d3e2426afee23103862a6b44105 to your computer and use it in GitHub Desktop.
Enable/Disable Natural Mouse Scrolling in Windows via PowerShell (requires restart to take effect)
param (
[Parameter(ParameterSetName = 'Enable', Mandatory)]
[switch]
$Enable,
[Parameter(ParameterSetName = 'Disable', Mandatory)]
[switch]
$Disable
)
function Set-MouseScrollDirection {
[CmdletBinding()]
param (
[ValidateSet('Natural', 'Relative')]
[string]
$ScrollType
)
begin {
Write-Debug "Enter [$($PSCmdlet.MyInvocation.MyCommand.Name)]..."
$PSBoundParameters.Keys.ForEach{
if ($PSBoundParameters.PSItem -is [string]) {
Write-Debug "$_ : $($PSBoundParameters.Item($_))"
} else {
Write-Debug "$_ : $($PSBoundParameters.Item($_).GetType())"
}
}
[int] $ScrollTypeValue = switch ($ScrollType) {
'Natural' {
1
}
'Relative' {
0
}
}
}
process {
# Get registry settings
$Properties = Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Enum\HID\*\*\Device Parameters' -Name FlipFlopWheel -EA 0
# Change registry settings
# Reverse mouse wheel scroll FlipFlopWheel = 1
# Normal mouse wheel scroll FlipFlopWheel = 0
$Properties.Where{ $PSItem.FlipFlopWheel -ne $ScrollTypeValue }.ForEach{ Set-ItemProperty -Path $PSItem.PSPath -Name FlipFlopWheel -Value $ScrollTypeValue -PassThru }
}
end {
Write-Debug "Exit [$($PSCmdlet.MyInvocation.MyCommand.Name)]..."
}
}
switch ($PSCmdlet.ParameterSetName) {
'Enable' {
Set-MouseScrollDirection -ScrollType Natural
}
'Disable' {
Set-MouseScrollDirection -ScrollType Relative
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment