This is a good topic.
You can actually get what window is your PC focusing on, like, what window will get your keyboard input. (This can be directly from the mu client's DLL. You are already working with Windows headers and libs in there, so it's not worth to make a new DLL and inject that into the main or main dll).
The client, while is in background or minimized, it's not checking for this and that's why, if you are alt tabbing the game or minimizing it, it would get tons of items by hitting space key, sometimes even writing in the in-game chat box.