Skip to content

Instantly share code, notes, and snippets.

@rbleattler
Created February 17, 2021 16:04
Show Gist options
  • Save rbleattler/7926380cefa33658c1067150eef49fb7 to your computer and use it in GitHub Desktop.
Save rbleattler/7926380cefa33658c1067150eef49fb7 to your computer and use it in GitHub Desktop.
PowerShell Mouse Scroll Wheel Tools
function Get-MouseScrollDirection {
[CmdletBinding()]
param (
)
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())"
}
}
}
process {
# Get registry settings
$Properties = Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Enum\HID\*\*\Device Parameters' -Name FlipFlopWheel -EA 0
$Properties.ForEach{ [pscustomobject]@{
Natural = $([bool]$PSItem.FlipFlopWheel)
Path = $PSItem.PSPath
}
}
}
end {
Write-Debug "Exit [$($PSCmdlet.MyInvocation.MyCommand.Name)]..."
}
}
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 1 }.ForEach{ Set-ItemProperty $PSItem.PSPath FlipFlopWheel $ScrollTypeValue }
}
end {
Write-Debug "Exit [$($PSCmdlet.MyInvocation.MyCommand.Name)]..."
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment