MS-Windows focus-follows-mouse Registry hacks

I like the "focus follows mouse" window-focussing model from X11, because

  • I don't have to click on the window, just move the mouse and the window it's over is focussed
  • I can focus a window without bringing it to the front, which is sometimes handy. If I want it in front, I can click it.

However MS-Windows follows the old-fashioned, Macintosh/Smalltalk style of having users click on a window to focus it for the keyboard. How do you make MS-Windows behave more like X11?

I used to install TweakUI from Microsoft, just so that I could turn on an X11-like focus-follows-mouse mode, but Microsoft don't make TweakUI for Vista (there is TweakVI instead, if you want to Google for it. It's by some other company. It's not bad, but overkill for what I want to do).

In Vista, Microsoft added a GUI for this mode that's almost what I want. You can do this:

Open Control Panel (new view, not Classic)

> Ease of Access Center

> Make the mouse easier to use

> [ ] Activate a window by hovering over it with the mouse

But this also brings the window to the front when it's focussed.  If that's what you want, then you're done. If you're like me and you want the window under the mouse to have keyboard focus, but you don't want it brought to the front without clicking on it, you'll need to hack the Windows Registry. Here are some steps, which should be good for any release of Windows that is based on Windows NT (NT, 2000, XP, Vista, Win7):

  1. Run regedit (Win+R, regedit, OK)
  2. Open up the key HKEY_CURRENT_USER\Control Panel\Mouse
  3. Change the value of the REG_DWORD ActiveWindowTracking to 0x0000001 (1)
  4. Open up the key HKEY_CURRENT_USER\Control Panel\Desktop
  5. Logical OR the first byte of the REG_BINARY UserPreferencesMask with 01.  That is, if the current value is df 3e 03 80 12 00 00 00, then leave the 'df' alone. If it's 9e 03 07 80 12 00 00 00 , change it to 9f .. ..  and so on *
  6. To make the focus a little slower, so that pop-up windows are useable, you also want to change the focus timing. Change the REG_DWORD ActiveWindTrkTimeout (also in HKEY_CURRENT_USER\Control Panel\Desktop) to the number of milliseconds to wait before focus shifts to the window under the mouse.  I like a value of 0x00000080 (128ms). You might like 200ms (c8), or some faster or slower value.

* If you can't do this hexadecimal bit twiddling math in your head (difficult if you're not a programmer), then Windows' Calc can do it for you: put it in Programmer and Hex modes, type the first byte (hex pair e.g. 9e), press the 'Or' button, then '1' and the '=' button.  If the number changes, that's what you replace the first byte with. Thanks to Erik in the comments below, I've finally figured this out and (I hope) clarified what to do..

So, in summary, the Registry keys are as follows for X11-like window focus:

HKEY_CURRENT_USERS\Control Panel\Mouse
  REG_DWORD ActiveWindowTracking = 0x00000001  (1)
HKEY_CURRENT_USERS\Control Panel\Desktop
  REG_DWORD ActiveWindTrkTimeout = 0x00000080  (128)
  REG_BINARY UserPreferencesMask OR= 01 .. .. .. .. .. .. .. ..

These registry hacks require a reboot to take effect.