I want to try to write a GUI program (called A) that can copy the window of another program (called B) to achieve the following effects:
The window of program B itself cannot be scaled, while the window of A can be scaled.
I can through window A, and the mouse event can be passed to window B, and at the same time make window B think that it is in focus. Since it is impossible for the two windows to let them be displayed simultaneously, B can only be in the background.
But I haven't found an existing library to capture these data at present, or is there any other implementation way?
Depending on the OS, the window manager, the compositor, and just the whole rendering system, hidden windows may or may not be rendered. On linux-with-x11, a solution could possibly be xvfb.
This feels like the sort of thing that might run foul of the OS’ security policies, because it can be used to make a keylogger program by pretending to be program B. (I don’t know if this is actually the case today, but would not be surprised if whatever mechanism you find gets locked down in the future)
Maybe it's really like what you said. However, I see that there are some programs on GitHub that can be used for zooming in and out of windows and can achieve a similar effect (of course, it doesn't create a new window but changes the original window), but I don't know how to implement it.
I don't think you can lie to a window about it being in focus, but if you could it would be through accessibility APIs; I think you'd have more luck actually having application B being in focus and avoiding application A taking focus, though I've not really tried to pull this off.