How do you enable focus follows mouse in Windows 10

Solution 1:

Use X-Mouse Controls, it's the closest I've found to true Focus Follows Mouse, and it has some options to tweak. It's a small open-source utility that doesn't require installing or rebooting, and saves you from changing the registry yourself.

As far as I've experimented, I can use the keyboard to search for files/programs after pressing the Win key. Also, Start and Notifications menu don't go away before I can use them, even with the raise-on-hover option, as you can set a small delay for the behavior (one or two hundred ms will suffice), which gives you more than enough room to move the pointer to the new window.

I've used it for a while and I'm quite happy with it, plus the bug.n tiling window manager. This setup is as close as I've been to using dwm on unix.

Solution 2:

The following powershell script should have the same effect as the XMouse program... without having to execute a 3rd party binary

Code:

$signature = @"
[DllImport("user32.dll")]
public static extern bool SystemParametersInfo(int uAction, int uParam, ref 
int lpvParam, int flags );
"@

$systemParamInfo = Add-Type -memberDefinition  $signature -Name SloppyFocusMouse -passThru

[Int32]$newVal = 1
$systemParamInfo::SystemParametersInfo(0x1001, 0, [REF]$newVal, 2)

Constants retrieved from here

Solution 3:

The registry modifications mentioned in the question's link do work on Windows 10. However, it seems they have to be made when the option “Activate a window by hovering over it with the mouse” is selected in the accessibility settings. This option can be found under Control Panel > Ease of Access > Change How Your Mouse Works.

This option also makes windows auto-raise, but the registry modifications stop this behaviour.

If you are experiencing the same issues and the checkbox is selected, unselect it, click apply, select it again and redo the modifications. The mouse should behave properly the next time you log in.

Solution 4:

Windows actually has a flag to enable focus-follows-mouse ("active window tracking"), which can be enabled easily via the monstrous "SystemParametersInfo" Win32 API call. There are third-party programs to enable the flag, such as X-Mouse Controls, or you can perform the call directly using PowerShell.

The documentation isn't always super clear on how the pvParam argument is used, and some powershell snippets incorrectly pass a pointer to the value, rather than the value itself, when setting this particular flag. This ends up always being interpreted as true, i.e. they accidently work for enabling the flag, but not for disabling it again.

Below is a powershell snippet that performs the call correctly. It also includes proper error-checking, and I've tried to go for cleanliness rather than brevity, to also make it easier to add wrappers for other functionality of SystemParametersInfo, should you find some that interests you.

Shout-out to pinvoke.net for being a helpful resource for stuff like this.

Add-Type -TypeDefinition @'
    using System;
    using System.Runtime.InteropServices;
    using System.ComponentModel;

    public static class Spi {
        [System.FlagsAttribute]
        private enum Flags : uint {
            None            = 0x0,
            UpdateIniFile   = 0x1,
            SendChange      = 0x2,
        }

        [DllImport("user32.dll", SetLastError = true)]
        private static extern bool SystemParametersInfo(
            uint uiAction, uint uiParam, UIntPtr pvParam, Flags flags );

        [DllImport("user32.dll", SetLastError = true)]
        private static extern bool SystemParametersInfo(
            uint uiAction, uint uiParam, out bool pvParam, Flags flags );

        private static void check( bool ok ) {
            if( ! ok )
                throw new Win32Exception( Marshal.GetLastWin32Error() );
        }

        private static UIntPtr ToUIntPtr( this bool value ) {
            return new UIntPtr( value ? 1u : 0u );
        }

        public static bool GetActiveWindowTracking() {
            bool enabled;
            check( SystemParametersInfo( 0x1000, 0, out enabled, Flags.None ) );
            return enabled;
        }

        public static void SetActiveWindowTracking( bool enabled ) {
            // note: pvParam contains the boolean (cast to void*), not a pointer to it!
            check( SystemParametersInfo( 0x1001, 0, enabled.ToUIntPtr(), Flags.SendChange ) );
        }
    }
'@

# check if mouse-focus is enabled
[Spi]::GetActiveWindowTracking()

# disable mouse-focus (default)
[Spi]::SetActiveWindowTracking( $false )

# enable mouse-focus
[Spi]::SetActiveWindowTracking( $true )

Solution 5:

For those who couldn't get it to work by just subtracting 40 from the first byte of UserPreferencesMask, just get the WinAero Tweaker utility itself at http://winaero.com/download.php?view.1796

Note that issue #1 above is still present, but easily worked around by just using the magnifying glass (search) icon to the right of the start menu (shortcut key Window + S). A small price to pay for getting X-Mouse functionality.

I don't experience issue #2 when I use WinAero Tweaker.