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.

About these ads

37 thoughts on “MS-Windows focus-follows-mouse Registry hacks

  1. Pingback: Tools of the trade (and other software) « Silly Features – Uri Gilad's Blog

  2. what happens though with the menus? I have made this change, however, I cannot get to press any options from the context menus (right click on the icons of the windows open in the taskbar)

    • Did you set the timeout to a larg-ish value? I haven’t had a problem with pop-up menus in the versions of Windows I tried this hack on (XP, Vista, 7). I did have a problem with some pop-ups for a third-party dock program, but I found slowing down the timeout fixes that (gives you time to put the mouse over the “window” so that it doesn’t disappear).

  3. Updated step 5 for clarity — you actually have to set the MSB to 01. Adding one to the value won’t cut it. Tested after a complete system rebuild of Windows 7 (for unrelated reasons).

  4. I recently followed your advice on my Win7 x64 machine to set up focus follows mouse without auto-raise, and by-and-large, this works fine except for Visual Studio 2008.

    But curiously, it’s not *all* VS – it’s only when a code window has focus within VS, that the (really annoying) auto-raise occurs.

    If I open another VS pane, such as Output or Breakpoints or whatever, click there, then move the mouse around, VS behaves correctly as far as focus-follows-mouse is concerned.

    Almost there, but not quite!

    • Yes I notice the same problem with a few other programs — Microsoft Office Communicator does this too, as does WinSCP. I think they might have some sort of Always On Top flag they use which is not working when the window is focussed but the flag not set (probably not a common condition for them to test!)

      The only work-around I’ve come up with is to install something like VirtuaWin and have these programs on their own desktop. Not really suitable for MOC, but could be okay for VS?

  5. VWM’s never really worked for me, though I did like the OpenLook VWM back in the day. Trouble was, I always forgot the open windows in the other desktops. For many years, have preferred everything bunched up in one desktop – hence my preference for focus-follows-mouse

  6. In the procedure step 5, it is advised to replace the value 3e with 01, but note that enameling ‘Activate a window by hovering over it with the mouse’ enables two bits with value 41. You need only the value 01. The other bits should not be touched. When I enabled ‘Activate a window by hovering over it with the mouse’ I got the value df and replaced it with 9f (subtracted 40).
    Note that the first number in the registry entry UserPreferencesMask that needs to be edited is not the MSB, but the LSB. Windows uses little endian notation for this entry.

  7. Pingback: Living with Windows 7 | Cats and Code

  8. Pingback: Focus Follows Mouse in Windows « Douglas Whitaker

  9. No registry hack is required. Setting is available in Ease of action center/Mouse settings in windows 7. After Activating a window by hovering the mouse over it window gets activated however the window comes in foreground while pushing the old window completely in background. I don’t want this. Previous window should not go into complete background it should stay and remain displayed. This was possible in Windows XP through Microsofts PowerTOY [TweakUI] application which is now not available for Windows7. Please help if you know any registry setting or anything to prevent the activated window to be activated only without forcefully coming to foreground similarly previous window should only get deactivated without disappearing or going to background. Note that all windows are obviously in resized state and not in maximized state.

    • Do you mean the “Activate window by hovering over it with mouse” option? That also brings to the front. This registry hack activates the window under the mouse, but without it coming to the front (in fact, no changes are made to the stacking order of windows, just the focus).

      I’ve not seen the behavior you describe where the previously activated window gets pushed to the back. Is that happening to you when you do this hack?

  10. Pingback: Adding some Tux to Windows 7 « Simple Scientist

  11. great post! misspelling, isn’t it “ActiveWndTrackTimeout” on win7? at least that entry was already present on a fresh win7.

    reg-file ready to use:
    =================
    Windows Registry Editor Version 5.00

    [HKEY_CURRENT_USER\Control Panel\Mouse]
    “ActiveWindowTracking”=dword:00000001

    [HKEY_CURRENT_USER\Control Panel\Desktop]
    ;dont bring window to the front (really only needed to set MSB / first byte to 01)
    “UserPreferencesMask”=hex:01,3e,07,80,12,00,00,00
    ;number of milliseconds to wait before focus shifts to the window under the mouse.
    “ActiveWndTrackTimeout”=dword:00000080

  12. OK, I did some more testing, this tweak seems not to work correctly anymore:
    a) occasionally a background window you are scrolling in is brought to foreground, especially with windows explorer
    b) using rightclick/context menu on entries in the taskbar is not possible anymore, when moving the mouse in the opened menu, focus is switched to the underlying window and the menu closes by itself.

    it seems this has to be solved programmatically… the tool AlwaysMouseWheel seems to work flawlessly so far.

  13. Brilliant, works on Windows 8.
    I first added a 01 as MSB in UserPreferencesMask (as given in the example above: “3e 03 80 12 00 00 00, then change it to 01 3e 03 80 12 00 00 00.”) and it did not work. Following the textual description to “Change the MSB [...] to 01″ worked (_replace_ the first value with 01, do not add a value 01).

  14. Very helpful. Works for Windows 7 x64. If we did want to raise the window to foreground after some delay, how would that be set?

  15. I also prefer the X11 action. I found a setting in Windows 7 that duplicated this (keyboard active, but window remains in background until selected with MB1). However, that laptop is gone and I now have Windows 8. If I find the setting on Windows 8, I will post.

  16. The right-click contect menu in the task-bar problem can be solved by right-clicking the icon (context windows pops up), and then right-click again. Now, keep the right button pressed down whilst selecting the option. Let go the right mouse button, and you’re done…

  17. Here (with Windows 7), I can right-click an icon on the task bar to bring up the context menu, then hold the LEFT mouse button down while moving the mouse cursor up into the menu. Once the mouse cursor is within the menu, I can release the button.

    • Yup, I have the same problem. Maybe if the delay was set it would give enough time to select from a menu. It might be a compromise. Otherwise, I agree, it doesn’t work.

      Does anyone have a fix?

      • There are more problems than just the right-clicking of icons on the task bar. Sometimes clicking on windows doesn’t bring them to front. In Windows Explorer, sometimes the right-click | Properties is for the folder not the file. Uhg. I’m undoing the change. It looks like there’s a reason it’s undocumented. :(

  18. Took forever to figure out that there’s a default ActiveWndTrackTimeout (which doesn’t do anything) and there’s a the real deal: ActiveWndTrkTimeout. Just gotta read more slowly…

    • Yes, that is what ActiveWndTrkTimeout controls. Specify time in milliseconds. Note the spelling of this key; as other commenters have stumbled over this too… I had “ActiveWindTrkTimeout” in the post, which is wrong too, I think. There’s also mentioned here ActiveWndTrackTimeout which is bogus too.

      I don’t have a Windows setup to play with this at the moment and tell you which spelling it is, you’ll have to experiment, sorry

  19. I’m very happy to uncover this great site. I want to to thank you for your time due to this wonderful read!! I definitely appreciated every part of it and i also have you saved to fav to check out new information in your site.

  20. Is this supposed to work like FocusFollowsMouse or SloppyFocusFollowsMouse? I think I had Sloppy… when I first implemented the hack, but now it works like Focus… Is there a bit to change the behavior?

    • sloppy, I think…? mouse over root window shouldn’t take focus, unless there’s a widget or something on the desktop. haven’t tried win8 so i can’t say if it has one of those ‘active desktop’ thingumies

      • I am on Windows 7. Here are a couple of possibilities, I am using the United States theme, so I wonder if the screen saver might be an application. The other thing is I am using VirtuaWin to manage multiple desktops. But I am pretty sure that it worked at one time.

  21. Hi, I would love to have this work on my windows 7, I followed the tutorial, my UserPreferenceMask is df 3e 07 12 00 00 00 ( ored with 01 )
    The activeWindowsTraking is 1
    but the windows still brings to the front !!
    what do I miss.
    thanks for help.

    • well I finally had to replace df by 01 instead of ored with 01 !
      but still some application like microsoft onenote still come up to front.

      • Well done! Ain’t Windows a bitch?
        Well I think someone else (or even me?) mentioned earlier that some window types aren’t cool with this hack.

        Sorry, I’m not being very helpful, hey? I think I’ll disable the comments on this, just because it’s not getting very much useful input now, and besides I’ve managed to escape from Windows except to have it in a VM for clients’ VPNs.

Comments are closed.