Look at the same question, which is slightly different from here.
Quote @Kevin Montrose: "Windows assumes that the activation window is the one that receives keyboard input. The correct way to fake keyboard input is SendInput, and you will notice that it only sends messages to the active window."
source
share