Prevent Automatic System Sleep


Please refer to antiSleep for more information.


How to Use

Introduction:

Anti-Sleep is used to prevent a Windows computer from entering automatic sleep mode within a specified period of time. Its core principle is to periodically simulate slight mouse movements to continuously trigger Windows’ user activity detection mechanism, allowing the system to determine that it is still in use, thus avoiding sleep or screen lock caused by long periods of inactivity. This solution does not modify the system power policy and is suitable for the following scenarios:

  • Long-running automation scripts
  • Device testing / stability testing
  • Preventing system sleep during presentations, screen sharing, or remote operations

Before Running:

  1. Suitable for Windows operating system
  2. Download and install Total Control 11.0 (Update 20) or later (Download)
  3. Save the example code as a .js file (e.g., TestAntiSleep.js) and place it in the Total Control default script directory
  4. Open the Script Terminal (Main Panel → Script → Terminal) and execute:
    >> sigmaLoad("TestAntiSleep.js");
    


Source Code

var antiSleep = require('sigma/antiSleep'); // Import the antiSleep module

// Configure default parameters:
// 1 = mouse movement interval (minutes)
// 2 = timeout (minutes)
antiSleep.configure(1, 2);

if (antiSleep) {
    var nudged = antiSleep.create(); // Create the anti-sleep task object
    if (nudged) {
        // Start the anti-sleep task
        // Parameter description:
        // 1 = move the mouse once every 1 minute
        // 5 = automatically stop the task after running for 5 minutes
        // If no parameters are passed, the default values set in configure() will be used
        nudged.start(1, 5);
    } else {
        print("create function failed.");
    }
} else {
    print(lastError());
}

Execution Result

antiSleep started: 1 min interval, auto stop in 5 min.

Printed during execution::

antiSleep nudged right-left
antiSleep nudged right-left
antiSleep nudged right-left
antiSleep nudged right-left
antiSleep auto timeout reached.

Note: When Total Control exits or the script finishes execution or is interrupted, the Anti-Sleep task will automatically terminate and will not leave any background processes running.


TCHelp