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)
|
Hi Anthony and welcome! So fortunately I just created a similar script a couple days ago for region-based window resizing using the Alt key. I made some changes for your use case, please read the script comments for button sequence, as it is not exactly the same, but is very close and I feel should be acceptable. I'll make this post for the resize, and another reply for the mover. Note that these both need to utilize the Mouse Events tab to handle the Left/Middle button release and the Capture Modifiers After setting in the action. The reason for this is that capturing modifiers after the stroke button is pressed means the Left/Middle button down event is captured and consumed by S+, so the app doesn't see it happen. In Chrome, it would start doing the middle button page scroll function, for example. So these scripts are designed for the least possible negative impact. It can be done in just the action script only, but you cannot do capture After (which absorbs the down event) and look to see if the button is still down...since S+ consumed it, Windows doesn't report the button as being held down. Hopefully this makes some sense! Resize Window By Region:Global Actions > Mouse Events > Middle Click (Script, do not check Consume Click Event)Code://Only do this on middle button release
// ! means NOT, so if the click event is NOT down
//(can only be Down or NOT Down [Up/Release]
if(!click.Down)
{
//Clean up variables and stop the timer script
sp.DeleteStoredPoint("ResizeLastCursorPos");
sp.DeleteStoredObject("ResizeStartRegion");
sp.DeleteStoredObject("ResizeWindow");
sp.DeleteTimer("ResizeWindowTimer");
sp.DeleteStoredBool("ResizeActive");
}
New Action - No Gesture, Middle Button modifier checked, Capture Modifiers: AfterCode:/*
This resizes the window based on a 3x3 grid, which determines how the window
will be resized based on where the mouse was within the window when the action started
Set action's Modifier as Middle Button, Capture Modifiers: After
You MUST begin holding the Middle button down AFTER pressing the stroke (right) button!
Sequence:
1. Stroke (right) button down
2. Middle button down (hold)
3. (optional draw gesture)
4. Stroke (right) button release
5. Move mouse to resize
6. Release middle button
*/
//Don't do anything if the window is maximized
if(!action.Window.Maximized)
{
//Get the region (from a 3x3 grid) where the action started and store that for use in the timer script
sp.StoreObject("ResizeStartRegion", sp.GetRegionFromPoint(action.Window.Rectangle, action.Start, 3, 3));
//Store the mouse location where the action ended (will be same as action.Start if no gesture)
sp.StorePoint("ResizeLastCursorPos", action.End);
//Store the reference to the window below the mouse where the action started
sp.StoreObject("ResizeWindow", action.Window);
//Create timer, ticks every 50ms until Middle is not being held down,
//which is handled in the Global Actions > Mouse Events > Middle Click tab
//NOTE the end of this line is a backtick, encompassing nearly everything below
sp.CreateTimer("ResizeWindowTimer", 50, 50, `
//Only do this if there isn't an active timer tick handling a resize
if(!sp.GetStoredBool("ResizeActive"))
{
//Signal so timer doesn't start concurrent resizing
sp.StoreBool("ResizeActive", true);
var startRegion = sp.GetStoredObject("ResizeStartRegion");
var lastPoint = sp.GetStoredPoint("ResizeLastCursorPos");
var currentPoint = sp.GetCurrentMousePoint();
var resizeTarget = sp.GetStoredObject("ResizeWindow");
var currentRect = resizeTarget.Rectangle;
var newRect = new Rectangle(currentRect.Location, currentRect.Size)
var xDiff = lastPoint.X - currentPoint.X;
var yDiff = lastPoint.Y - currentPoint.Y;
//Only do this next set of logic if the mouse has moved
if(xDiff !== 0 || yDiff !== 0)
{
if(startRegion.Row === 1)
{
//Top row --------------------------------
if(startRegion.Column === 1)
{
//Top left
newRect.Location = new Point(currentRect.X - xDiff, currentRect.Y - yDiff);
newRect.Width = currentRect.Width + xDiff;
newRect.Height = currentRect.Height + yDiff;
}
else if(startRegion.Column === 2)
{
//Top center
newRect.Location = new Point(currentRect.X, currentRect.Y - yDiff);
newRect.Height = currentRect.Height + yDiff;
}
else if(startRegion.Column === 3)
{
//Top right
newRect.Location = new Point(currentRect.X, currentRect.Y - yDiff);
newRect.Width = currentRect.Width - xDiff;
newRect.Height = currentRect.Height + yDiff;
}
}
else if(startRegion.Row === 2)
{
//Center row --------------------------------
if(startRegion.Column === 1)
{
//Center left
newRect.Location = new Point(currentRect.X - xDiff, currentRect.Y);
newRect.Width = currentRect.Width + xDiff;
}
else if(startRegion.Column === 2)
{
//Center - Scale? Up/Down & Left/Right
newRect.Location = new Point(currentRect.X + parseInt(xDiff / 2), currentRect.Y - parseInt(yDiff / 2));
newRect.Width = currentRect.Width - xDiff;
newRect.Height = currentRect.Height + yDiff;
}
else if(startRegion.Column === 3)
{
//Center right
newRect.Width = currentRect.Width - xDiff;
}
}
else if(startRegion.Row === 3)
{
//Bottom row --------------------------------
if(startRegion.Column === 1)
{
//Bottom left
newRect.Location = new Point(currentRect.X - xDiff, currentRect.Y);
newRect.Width = currentRect.Width + xDiff;
newRect.Height = currentRect.Height - yDiff;
}
else if(startRegion.Column === 2)
{
//Bottom center
newRect.Height = currentRect.Height - yDiff;
}
else if(startRegion.Column === 3)
{
//Bottom right
newRect.Width = currentRect.Width - xDiff;
newRect.Height = currentRect.Height - yDiff;
}
}
//Assign window size to new rectangle
resizeTarget.Rectangle = newRect;
//Store current mouse point as last location
sp.StorePoint("ResizeLastCursorPos", currentPoint);
}
//Allow next timer tick to process resizing
sp.StoreBool("ResizeActive", false);
}
`); //End of Timer script parameter
}
Edited by user Wednesday, October 28, 2020 2:34:24 PM(UTC)
| Reason: Not specified
|