It works like this:
1. The keyboard says: Key 9 has been pressed (KeyDown event).
2. The PC (OS) looks up what keyboard is attached and what the current input language is. It loads the corresponding code table and checks the state of the shift keys: Alt should be pressed as well.
3. It generates a KeyPressed event for keycode Alt-Tab.
4. This triggers the switch foreground application event, and now (for example) the Explorer/File manager is active.
5. The Tab key is released and pressed again, which generates the corresponding KeyUp and KeyDown events.
6. That last event triggers a new switch foreground application event, and the focus switches back to your application. This takes a while, and the user releases both keys.
7. Your application becomes active. And, because you're handling and decoding the keyboard yourself, you know for sure that the Alt key is pressed down (which it isn't). So all new key presses are handled wrong, until the user presses the Alt key and your application notices that it wasn't actually pressed.