Note, this only gets key and mouse events that were waiting to be processed while your macro was running. Key/mouse events that were processed normally before your macro blocked input will not be returned by this method, as they are long gone.

You actually do not need the FindWindow API function, since VBA provides a built-in way to get the Excel window handle, provided by Ken above. Thanks Ken!