I'm a fan of the sloppy mouse focus model, where focus follows the mouse cursor except when the cursor is over the desktop or the task bar. Only recently did I find that this can be enabled in Windows by twiddling a bit in the registry.
The particular registry key is: HKEY_CURRENT_USER\Control Panel\Desktop\UserPreferencesMask.
Setting the least significant bit of the first byte enables this focus model. To make this easier, I've written the following PowerShell function:
- # Enable or disable 'Sloppy' mouse focus. Effective on the next login.
- function Set-SloppyMouseFocus([switch]$Enable)
- # Read user preferences mask.
- $regKeyPath = "HKCU:\Control Panel\Desktop\"
- $prefs = $(Get-ItemProperty $regKeyPath).UserPreferencesMask
- # Index into UserPreferencesMask where the relevant flag resides.
- $flag = 0x0
- # Bit in UserPreferencesMask[$flag] which sets sloppy mouse focus.
- $sloppy = 0x01
- if ($Enable)
- Write-Host "Enabling 'Sloppy' mouse focus."
- $prefs[$flag] = $prefs[$flag] -bor $sloppy
- Write-Host "Disabling 'Sloppy' mouse focus."
- $sloppy = -bnot $sloppy
- $prefs[$flag] = $prefs[$flag] -band $sloppy
- # Update UserPreferencesMask.
- Set-ItemProperty -Path $regKeyPath -Name UserPreferencesMask -Value $prefs
To enable Sloppy focus, save that snippet as a file and dot-source it, then execute Set-SloppyMouseFocus -Enable.
- . .\Set-SloppyMouseFocus.ps1
- Set-SloppyMouseFocus -Enable
This is particularly useful if you're using multiple monitors.
Credit for this goes to Scurvy Jake's Pirate Blog.