I posted a possible answer to your question, though as I pointed out in the answer, it's not a general answer. It might work for your use case, and if it does, that's great. Notably, it doesn't work for me, I had to test it out in a VM, since my machine is sufficiently locked down there is no real way to disable the screen saver from code and return to the active session .. by design.
What do I do in a situation like this?
Answering this meta question is hard. Really, at the heart of things, we have an XY problem. I try to answer for the general case on Stack Overflow. For the general case for your question the answer is "don't do that. Use SetThreadExecutionState
to prevent the screen saver from running, show a full-screen top-most window to act as a screen saver and make it flash or otherwise alert the user when your condition is meet"
That's however super not satisfying when you expect the answer to be a simple "call foo() to move the mouse cursor and disable the screen saver". You just need to know what "foo()" is! And to make matters worse, there is a "foo()", I showed you one possibility of it after all. The other answer around terminating a process works too, albeit in a way that's a bit like using a bomb to open a jar of pickles.
I know I personally struggle to know when to answer these sort of questions as is, and not worry about the inherent XY problem, and when to go into little dissertations about the XY problem and solve the underlying problem. It's a balancing act, and sometimes things are missed, since I tend to just skip over things that make me struggle internally since previous encounters with others has taught me people just want answers, not more problems.
I'm open to suggestions here.