This is already done though? It's known as focus stealing prevention. One of my gripes with Linux is that it doesn't work well there, but I've found it is already very well handled in Windows; the trouble only comes up if (a) you pause too long for it to realize you're still typing, or (b) the app goes VERY out of its way to steal your keyboard (like hooking global keyboard messages) which is extremely abnormal. I'm surprised if you regularly experience otherwise.