On my 4k screens, I like to crank up the mouse pointer size in windows.

This is great for 95% of usage, but sometimes I need a small mouse pointer again for finer-precision work.
Unhappy that I have to open settings each time, I want a keyboard shortcut that I can use to toggle between big mouse and small mouse.
So I composed the following in the hope it would do the trick:
- Update the registry with the new mouse size setting
- Call
SystemParametersInfo()with parameterSPI_SETCURSORSto jog the system to re-read the mouse settings.
Alas, no joy.
Can anyone point out the folly of my ways? Cheers, Dave
Code below:
param([int]$MouseSize=0)
###########################################
#
# DISAPPOINTINGLY THIS DOES NOT YET WORK
# Need to figure out why
#
###########################################
##################
# Constants
##################
[int]$small_mouse = 48
[int]$big_mouse = 80
[int]$min_mouse = 1
[int]$max_mouse = 256
[string]$path = 'HKCU:\Control Panel\Cursors'
[string]$name = 'CursorBaseSize'
##################
# API Import
##################
Try{
[void][SysParams]
} Catch {
Add-Type @'
using System;
using System.Runtime.InteropServices;
public class SysParams {
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool SystemParametersInfo(uint uiAction, uint uiParam, uint pvParam, uint fWinIni);
public static bool RefreshCursor()
{
return SystemParametersInfo(0x0057, 0, 0, 0); // SPI_SETCURSORS = 0x0057;
}
}
'@
}
##################
# Main
##################
# Is $MouseSize passed in valid?
if ($MouseSize -ge $min_mouse -and $MouseSize -le $max_mouse) {
$new_size = $MouseSize
} else {
# If invalid $MouseSize passed in, toggle current mouse setting
# First determine if current setting closer to $small_mouse or $big_mouse
$current_size = (Get-ItemProperty $path).$name
$diff_small = [math]::Abs($current_size - $small_mouse)
$diff_big = [math]::Abs($current_size - $big_mouse)
if ($diff_small -lt $diff_big) {
$new_size = $big_mouse # Mouse is small, so toggle big
} else {
$new_size = $small_mouse # Mouse is big, so toggle small
}
}
Set-ItemProperty -Path $path -Name $name -Value $new_size
$resp = [SysParams]::RefreshCursor()