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):
- Run regedit (Win+R, regedit, OK)
- Open up the key HKEY_CURRENT_USER\Control Panel\Mouse
- Change the value of the REG_DWORD ActiveWindowTracking to 0×0000001 (1)
- Open up the key HKEY_CURRENT_USER\Control Panel\Desktop
- Change the MSB (most significant byte) of the REG_BINARY UserPreferencesMask to be 01. That is, if the current value is df 3e 03 80 12 00 00 00, then change it to 01 3e 03 80 12 00 00 00. If you used the GUI as above, the MSB might be 41 (which brings the focused window to the front as well), so change it back to 01.
- 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 0×00000080 (128ms). You might like 200ms (c8), or some faster or slower value.
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 = 01 .. .. .. .. .. .. .. ..
These registry hacks require a reboot to take effect.
Pingback: Tools of the trade (and other software) « Silly Features – Uri Gilad's Blog
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).
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).
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?
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
Thank you, this works nicely and makes a huge difference (Win7 x64).
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.
Pingback: Living with Windows 7 | Cats and Code
Thanks ever so much. This is great.
Pingback: Focus Follows Mouse in Windows « Douglas Whitaker
http://technet.microsoft.com/en-us/library/cc957204 appears to document this entry, and it looks like setting the whole LSB to 01 will affect a bunch of other settings. As Erik said, it looks like we need to set bit 0 to 1 and bit 6 to 0 to make this work, but I haven’t yet rebooted to check.
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?
Pingback: Adding some Tux to Windows 7 « Simple Scientist
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
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.
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).
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?
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.
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…