settings

Why

In macOS and Linux world, users can configure their mouse scroll direction conveniently with a provided settings UI or human readable config file. In Windows it's a completely different story, you won't find anything in settings UI, and Windows doesn't use config files, instead, it uses registry (which everybody hates).

Well if you google it, you might find some tutorials that tell you to look up your mouse device ID and then modify the registry. I went through that and I think it will be very useful if I wrote a script.

So here we are.

How to

Find your mouse

$mouses = Get-CimInstance -ClassName Win32_PointingDevice | Where-Object Name -Match "USB Input Device"
$mouses += Get-CimInstance -ClassName Win32_PointingDevice | Where-Object Name -Match "HID-compliant mouse"

If you use a wired USB mouse, you will only need the first line, but it doesn't hurt to have both.

Now you loop through $mouses to set up each mouse, in general you have only one mouse, sometimes with a touchpad (which we will skip, for natural scroll is enabled for touchpads by default).

Modify scroll direction

Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Enum\$path\Device Parameters" -Name FlipFlopWheel -Value 1 # if you want to change it back, set it to 0

Where path can be retrieved by:

$usb_mouse = $mouse.DeviceID
$id = $usb_mouse.split("\\")[1]
$device = Get-PnpDevice -PresentOnly -Class Mouse | Where-Object DeviceID -Match $id 
$name = $device | Select-Object -ExpandProperty FriendlyName
$path = $device | Select-Object -ExpandProperty InstanceId

The script

You can find the latest version here.

Write-Host "Finding your USB mouse..." -ForegroundColor Cyan

$mouses = Get-CimInstance -ClassName Win32_PointingDevice | Where-Object Name -Match "USB Input Device"
$mouses += Get-CimInstance -ClassName Win32_PointingDevice | Where-Object Name -Match "HID-compliant mouse"
if (!$mouses) {
    Write-Host -ForegroundColor Red "Could not find your USB mouse"
    exit 1
}

# set up every mouse 
foreach ($mouse in $mouses) {
    if (!($mouse.DeviceID -like "HID\VID*")) {
        Write-Host -ForegroundColor Yellow "Skipping"$mouse.DeviceID
        continue
    }
    Write-Host -ForegroundColor Blue "We have"$mouse.DeviceID
    $usb_mouse = $mouse.DeviceID
    $id = $usb_mouse.split("\\")[1]
    $device = Get-PnpDevice -PresentOnly -Class Mouse | Where-Object DeviceID -Match $id 
    $name = $device | Select-Object -ExpandProperty FriendlyName
    $path = $device | Select-Object -ExpandProperty InstanceId

    Write-Host "Found $name ($path)" -ForegroundColor Green 
    Write-Host "Configuring natural scrolling feature for your mouse..." -ForegroundColor Cyan

    $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
    if (!$currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
        Write-Host -ForegroundColor Red "Need admin privilege to modify the registry"
        exit 1
    }

    if ($args[0] -eq "reverse") {
        Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Enum\$path\Device Parameters" -Name FlipFlopWheel -Value 0
        Write-Host "Natural scrolling feature for your mouse has been DISABLED" -ForegroundColor Green
        exit
    }
    Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Enum\$path\Device Parameters" -Name FlipFlopWheel -Value 1
    Write-Host "Natural scrolling feature for your mouse has been ENABLED" -ForegroundColor Green
}

Comments

comments powered by Disqus