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

Notification

Icon
Error

Options
Go to last post Go to first unread
randomConstant  
#1 Posted : Monday, December 20, 2021 6:56:53 PM(UTC)
randomConstant

Rank: Advanced Member

Reputation:

Groups: Translators, Approved
Joined: 7/17/2021(UTC)
Posts: 74
Pakistan

Thanks: 15 times
Was thanked: 8 time(s) in 7 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
Rob  
#2 Posted : Monday, December 20, 2021 8:45:44 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,109
United States
Location: Tampa, FL

Thanks: 24 times
Was thanked: 336 time(s) in 293 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.zip

That'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.dll

You may have to restart S+ after adding the plug-in

Then 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) 
);
thanks 1 user thanked Rob for this useful post.
randomConstant on 12/21/2021(UTC)
Rob  
#3 Posted : Monday, December 20, 2021 9:02:35 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,109
United States
Location: Tampa, FL

Thanks: 24 times
Was thanked: 336 time(s) in 293 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

Rob  
#4 Posted : Tuesday, December 21, 2021 3:54:19 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,109
United States
Location: Tampa, FL

Thanks: 24 times
Was thanked: 336 time(s) in 293 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);
thanks 1 user thanked Rob for this useful post.
randomConstant on 12/21/2021(UTC)
randomConstant  
#5 Posted : Tuesday, December 21, 2021 7:02:28 AM(UTC)
randomConstant

Rank: Advanced Member

Reputation:

Groups: Translators, Approved
Joined: 7/17/2021(UTC)
Posts: 74
Pakistan

Thanks: 15 times
Was thanked: 8 time(s) in 7 post(s)
Yup, exactly what I needed. Thanks Rob! Laugh

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 Unsure
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
Rob  
#6 Posted : Tuesday, December 21, 2021 4:30:04 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,109
United States
Location: Tampa, FL

Thanks: 24 times
Was thanked: 336 time(s) in 293 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.
randomConstant  
#7 Posted : Tuesday, December 21, 2021 7:49:21 PM(UTC)
randomConstant

Rank: Advanced Member

Reputation:

Groups: Translators, Approved
Joined: 7/17/2021(UTC)
Posts: 74
Pakistan

Thanks: 15 times
Was thanked: 8 time(s) in 7 post(s)
Thanks for the tips Rob. Laugh

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
Rob  
#8 Posted : Tuesday, December 21, 2021 10:55:52 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,109
United States
Location: Tampa, FL

Thanks: 24 times
Was thanked: 336 time(s) in 293 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.

Byte

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? BigGrin

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

thanks 1 user thanked Rob for this useful post.
randomConstant on 12/22/2021(UTC)
randomConstant  
#9 Posted : Wednesday, December 22, 2021 12:23:40 PM(UTC)
randomConstant

Rank: Advanced Member

Reputation:

Groups: Translators, Approved
Joined: 7/17/2021(UTC)
Posts: 74
Pakistan

Thanks: 15 times
Was thanked: 8 time(s) in 7 post(s)
Oh I see, that makes sense.

Thanks Rob Laugh
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.