Search code examples
objective-cmacosscreensaver

how to make a screensaver that stays in screensaver when moving mouse in Mac OS?


I want to make a screensaver in Mac OS 10.8. And I'd love to stay in the screensaver when mouse moves. To exit the screensaver, clicking a button is needed. Does anyone have ideas about this? Thanks!


Solution

  • I don't have a full answer as I'm not sure how to capture mouse events in OSX, but if your screen saver code is running without any idle time, it won't exit no matter what the user does. To exit the screen saver, the OS needs to be given some idle time to check for user input (like mouse movement, key presses, etc.). Thus, on the very first drawRect call you could initiate a while loop to check for mouse clicking; if the mouse is never clicked, control stays within your loop and the screen saver will not exit. Everything you want the screen saver to do will thus have to stay within that loop.

    Does that help?