Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,359 Location: Tampa, FL Thanks: 28 times Was thanked: 419 time(s) in 356 post(s)
|
Create a timer that periodically moves the mouse to keep the computer active, and a timer to remind you that it's running. I have this bound to a hotkey, but it work with an action as well. Code://Create the display popup for the hot key press event
var info = new DisplayTextInfo();
info.Title = "NoSleep";
info.Duration = 1000;
info.Opacity = 0.8;
info.Location = "top";
info.TitleFont = new Font("Segoe UI", 12, host.flags(FontStyle.Bold));
info.MessageFont = new Font("Segoe UI", 12);
info.ForeColor = "white";
info.Padding = 15;
info.UsePrimaryScreen = true;
//See if there's already a NoSleep timer, if not create and start a new set
//if there is, then we're going to stop the timers
var tmr = sp.GetTimer("NoSleep");
if(tmr == null)
{
//Create the reminder timer, this will show a quick display popup
//every 30 minutes to let you know this is still running
sp.CreateTimer("NoSleepReminder",
1800100,
1800100,
String.raw` var info = new DisplayTextInfo();
info.Title = "NoSleep";
info.Duration = 1000;
info.Opacity = 0.8;
info.Location = "top";
info.TitleFont = new Font("Segoe UI", 12, host.flags(FontStyle.Bold));
info.MessageFont = new Font("Segoe UI", 12);
info.ForeColor = "white";
info.BackColor = "blue";
info.Message = "NoSleep Timer Still Running";
info.Padding = 15;
info.UsePrimaryScreen = true;
sp.DisplayText(info);`
);
//Create the main timer, which moves the mouse 5px and back
//every 10 seconds, but only if the mouse hasn't moved since the
//last timer
sp.CreateTimer("NoSleep",
10000,
10000,
String.raw` var lp = sp.GetStoredPoint("lastMousePoint");
var currpt = sp.GetCurrentMousePoint();
if(lp != null) {
if(lp.X == currpt.X && lp.Y == currpt.Y) {
sp.MouseMove(new Point(currpt.X + 5, currpt.Y +5));
sp.Sleep(200);
sp.MouseMove(currpt);
}
}
//Store the current mouse location for the next timer sheck
sp.StorePoint("lastMousePoint", currpt);`
);
//Set the hot key press popup color and text, to display when
//the hot key is fired. This text is for when you're starting the timer.
info.BackColor = "green";
info.Message = "NoSleep Timer STARTED";
} else {
//Set the hot key press popup color and text, to display when
//the hot key is fired. This text is for when you're stopping the timer.
info.Message = "NoSleep Timer STOPPED";
info.BackColor = "red";
//Stop and delete both the main and reminder timers, remove the stored point
sp.DeleteTimer("NoSleep");
sp.DeleteTimer("NoSleepReminder");
sp.DeleteStoredPoint("lastMousePoint");
}
//Show the display popup for when the hot key is pressed, showing either
//that the timer was started or stopped
sp.DisplayText(info);
|