I had the same problem on my MacBookAir (13" Early 2015) after recent upgrade of MacOS Sierra 10.2.2. After 4-5 seconds of typing in any window, it would revert back to the desktop focus. Very frustrating, until I noticed a small icon appearing and then disappearing on the top desktop bar to the right when this problem occurred. I finally was able to catch the icon and it was Razer Synapse program. I then searched for Razer in my finder and it come up with Razer Synapse Uninstaller. I ran this, uninstalled the program and it restarted my computer. After this it hasn't occurred again and no programs exist on my computer with the word Razer in it. I hope this helps.