logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Rob  
#1 Posted : Tuesday, January 29, 2019 6:33:08 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 28
United States

Was thanked: 9 time(s) in 5 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);
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.