StrokesPlus.net
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: 340
United States

Thanks: 5 times
Was thanked: 64 time(s) in 56 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);
2014218866  
#2 Posted : Monday, September 9, 2019 11:45:08 PM(UTC)
2014218866

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 5/6/2019(UTC)
Posts: 50
China

Thanks: 9 times
Dear Rob,
can it achieve different functions by the length of time it takes to press keys (including mouse buttons, keyboard keys, and the time it takes to draw a gesture).
For example, the press time of the wheel key (or Alt) is less than 500 ms to perform one function, and more than 500 ms to perform another function. Thank you for your reply.
Rob  
#3 Posted : Tuesday, September 10, 2019 7:29:50 AM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 5 times
Was thanked: 64 time(s) in 56 post(s)
Nothing is built-in to support that, you would have to handle that in scripts. But you might not be able to handle every situation.

But in general, you would have to use GetKeyState, javascript date, and storing values, then tracking/comparing those values to determine what action should happen. But things like how long to draw the gesture wouldn't be available since the script wouldn't execute until after the gesture was drawn. However, you can use point counts or distance in your script to do different things based on the length of the gesture, for example.
thanks 1 user thanked Rob for this useful post.
2014218866 on 9/10/2019(UTC)
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.