Rank: Advanced Member
Groups: Translators, Approved Joined: 7/17/2021(UTC) Posts: 135
Thanks: 35 times Was thanked: 18 time(s) in 15 post(s)
|
Hi all,
As the description says, I'd like to make a rectangle (such as using new Rectangle()) and fill it with a solid color, or an image. For instance make the entire monitor screen appear as if it is turned OFF.
Is this possible using S+?
Thanks
|
|
|
|
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)
|
This is something better suited to a plugin, so it doesn't tie up the script engines. https://www.strokesplus.net/files/plugins/SolidTopRectangle_1.0.zipThat's the entire source code, took about 5 minutes to create in Visual Studio 2019 Community Edition (free). After extracting go to S+ > Plug-Ins > Add Plug-In and select the file: SolidTopRectangle\bin\Debug\SolidTopRectangle.dllYou may have to restart S+ after adding the plug-inThen create as many rectangles you want: Code://Can also use System.Drawing.Color.FromArgb(r, g, b)
//https://docs.microsoft.com/en-us/dotnet/api/system.drawing.color.fromargb?view=netframework-4.8
// new Rectangle ctor:
//https://docs.microsoft.com/en-us/dotnet/api/system.drawing.rectangle.-ctor?view=netframework-4.8
new CreateSolidRectangle(
System.Drawing.Color.Black,
new System.Drawing.Rectangle(0, 0, 500, 500)
);
|
1 user thanked Rob for this useful post.
|
|
|
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)
|
Oh yeah, double-click the rectangle to close it. Though it is just a window and recognizes gestures like maximize and close as well. Edited by user Tuesday, December 21, 2021 3:45:26 AM(UTC)
| Reason: Not specified
|
|
|
|
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)
|
This is actually handy! I created an action to cover the whole screen in a black rectangle and move the mouse to the far right - so it's like all screens are off. Code:new CreateSolidRectangle(
System.Drawing.Color.Black,
System.Windows.Forms.SystemInformation.VirtualScreen
);
StrokesPlus.Delay.Pause(1);
StrokesPlus.Input.Mouse.Location = new Point(sysinfo.VirtualScreen.Right, 0);
|
1 user thanked Rob for this useful post.
|
|
|
Rank: Advanced Member
Groups: Translators, Approved Joined: 7/17/2021(UTC) Posts: 135
Thanks: 35 times Was thanked: 18 time(s) in 15 post(s)
|
Yup, exactly what I needed. Thanks Rob! I can lock the mouse to a corner but can not stop user from doubling clicking it or pressing ALT-TAB and noticing that the machine is in fact running I guess I'll need to try and implement those mouse and keyboard input consuming hooks after all. The reason I'm taking this long approach over simply locking the machine is because sometimes there are things running in a browser over a VPN and some other things downloading and so on which I do not want to halt by locking the system when I step away from it. I will also try to tweak the plugin source code in VS as I've never made plugins and want to see how its done. I'm assuming the .dll files will be created when I test or run the project in VS. Thanks
|
|
|
|
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)
|
Yeah, when you build the project, the DLL in the Debug or Release folder (depending on selected build configuration) will be recompiled.
Then you just re-add the plugin DLL and restart S+.
Also, you can add the output folder to the S+ plugin Search Locations, so then you just build and restart S+ instead of going through extra steps.
--
Regarding the overall plan, it might be easiest to just create a timer which consumes all input, and have the interval be every x seconds to run.
When it fires, the script turns off consume physical, waits a brief moment, then check the key state to see if Escape is being held down or something, and if not consumes input again.
|
|
|
|
Rank: Advanced Member
Groups: Translators, Approved Joined: 7/17/2021(UTC) Posts: 135
Thanks: 35 times Was thanked: 18 time(s) in 15 post(s)
|
Thanks for the tips Rob. This code is working fine for me now. Code://make a black rectangle to cover the screen
new CreateSolidRectangle(
System.Drawing.Color.Black,
System.Windows.Forms.SystemInformation.VirtualScreen
);
//start a timer, firing every 2000 ms
sp.CreateTimer('ConsumeInput', 0, 2000, String.raw`
//allow normal input
sp.ConsumePhysicalInput(false);
//lock the mouse cursor to a corner
StrokesPlus.Input.Mouse.Location = new Point(sysinfo.VirtualScreen.Right, 0);
sp.MouseRestrictToRectangle(new Rectangle(sp.GetCurrentMousePoint().X, sp.GetCurrentMousePoint().Y, 0, 0));
sp.Sleep(100);
//check if unlock key is pressed, 'F1' in this case
if(sp.GetKeyState(vk.F1) & 0x8000){
//unlock mouse cursor, double click to close rectangle and delete the timer
sp.MouseRestrictClear();
sp.MouseClick(new Point(sp.GetCurrentMousePoint().X, sp.GetCurrentMousePoint().Y), MouseButtons.Left, true, true);
sp.MouseClick(new Point(sp.GetCurrentMousePoint().X, sp.GetCurrentMousePoint().Y), MouseButtons.Left, true, true);
sp.DeleteTimer('ConsumeInput');
}else{
sp.ConsumePhysicalInput(true, 0);
}
`);
One question though, I've been adding this & 0x8000 whenever I'm checking for a keystate because I've seen it being used this way in the forum before. I'm guessing its an Octal number, may I please know what it is used for here? Thanks
|
|
|
|
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)
|
GetKeyState in S+ actually calls GetAsyncKeyState (there are reasons...) and that returns a signed integer. However, many Windows API functions utilize different parts of numbers to store different values, often referred to as the high order and low order bytes (high order is the left byte in the image below, low order is the right byte). Using the logical operation value AND 0x8000 essentially removes everything except the most significant bit (MSB), which is what Microsoft says is the one which indicates if the key is being currently pressed. 0x8000 (hex) in binary is 1000 0000 0000 0000 - so you're taking the return value and saying, ignore everything after the MSB, then only when the first (left, most significant) bit is 1 (like 0x8000's MSB which is 1 / 1 AND 1 == 1 / 1 == true) - then we know the key is pressed down. Perfectly clear, right? Edit: Additional info, AND means both aligned bits must be 1 to result in 1 Code: 1010 1111 0101 1010 (imaginary value returned from GetKeyState)
AND 1000 0000 0000 0000 (hex 0x8000 since only the first bit is 1, all others will always result in 0)
-----------------------
= 1000 0000 0000 0000 (since both of the first bits are 1, it results in 1 - not 0,
so in JavaScript if statement, this will be true)
Edited by user Wednesday, December 22, 2021 3:04:23 AM(UTC)
| Reason: Not specified
|
1 user thanked Rob for this useful post.
|
|
|
Rank: Advanced Member
Groups: Translators, Approved Joined: 7/17/2021(UTC) Posts: 135
Thanks: 35 times Was thanked: 18 time(s) in 15 post(s)
|
Oh I see, that makes sense. Thanks Rob
|
|
|
|
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.
Important Information:
The StrokesPlus.net Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close