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

Notification

Icon
Error

Options
Go to last post Go to first unread
petercncn  
#1 Posted : Thursday, November 5, 2020 8:01:50 AM(UTC)
petercncn

Rank: Newbie

Reputation:

Groups: Approved
Joined: 11/4/2020(UTC)
Posts: 5
China

SP+net is really a good software. I had moved to SP+net from SP+ before two years ago. And rencently, I also find a very good Autohotkey script. But it is conflicting to SP+net in some of the hotkeys.

The most important feature of the Autohotkey script (named NiftyWindows, open source) uses mouse RIGHT_BUTTON + DRAG to change the size of every window in a very fast and convinient way. After you try this function, I bet you will also love it. Since the RIGHT_BUTTON + DRAG is used by SP+net, I modify the NiftyWindows' code adding an IF to check if the LEFT _BUTTON is pressed first, so I can use hotkeys LEFT _BUTTON + RIGHT_BUTTON + DRAG (suspend SP+net first) to perform changing the size of any window. But when I enable SP+net, the function in that Autohotkey script is disable. I guess SP+net can get the hook of mouse RIGHT_BUTTON better than Autohotkey.

The introdution of NiftyWindows Autohotkey script: http://www.enovatic.org/...s/niftywindows/features/
RIGHT_BUTTON+DRAG : This is the most powerful feature of NiftyWindows. The area of every window is tiled in a virtual 9-cell grid with three columns and rows. The center cell is the largest one and you can grab and move a window around by clicking and holding it with the right mouse button. The other eight corner cells are used to resize a resizable window in the same manner with different ways.


I want to solve the problem. I suggest that when I press left mouse button, SP+net should not get the hooks of left and right buttons, and in the next half of a second when I press right mouse button and drag the mouse, the Autohotkey can get the hooks of left and right buttons to perform the function I mentioned above.

Or can anybody transfer the Autohotkey scripts of size control of windows to SP+net? Then I will use hotkey LEFT _BUTTON + RIGHT_BUTTON + DRAG (or RIGHT_BUTTON + LEFT _BUTTON + DRAG) to change every window in very convinient way. If someone may transfer the script, will SP+net let me perform the function in the script when I use RIGHT_BUTTON + LEFT _BUTTON + DRAG and SP+net will not draw any gesture?


I post the main Autohotkey script below:
$RButton::
$+RButton::
$+!RButton::
$+^RButton::
$+#RButton::
$+!^RButton::
$+!#RButton::
$+^#RButton::
$+!^#RButton::
$!RButton::
$!^RButton::
$!#RButton::
$!^#RButton::
$^RButton::
$^#RButton::
$#RButton::
GetKeyState, Peter_LButtonState, LButton, P
If ( (Peter_LButtonState = "D") and (!NWD_ImmediateDown))
{

NWD_ResizeGrids = 5
CoordMode, Mouse, Screen
MouseGetPos, NWD_MouseStartX, NWD_MouseStartY, NWD_WinID
If ( !NWD_WinID )
Return
WinGetPos, NWD_WinStartX, NWD_WinStartY, NWD_WinStartW, NWD_WinStartH, ahk_id %NWD_WinID%
WinGet, NWD_WinMinMax, MinMax, ahk_id %NWD_WinID%
WinGet, NWD_WinStyle, Style, ahk_id %NWD_WinID%
WinGetClass, NWD_WinClass, ahk_id %NWD_WinID%
GetKeyState, NWD_CtrlState, Ctrl, P

; the and'ed condition checks for popup window:
; (WS_POPUP) and !(WS_DLGFRAME | WS_SYSMENU | WS_THICKFRAME)
If ( (NWD_WinClass = "Progman") or ((NWD_CtrlState = "U") and (((NWD_WinStyle & 0x80000000) and !(NWD_WinStyle & 0x4C0000)) or (NWD_WinClass = "ExploreWClass") or (NWD_WinClass = "CabinetWClass") or (NWD_WinClass = "IEFrame") or (NWD_WinClass = "MozillaWindowClass") or (NWD_WinClass = "OpWindow") or (NWD_WinClass = "ATL:ExplorerFrame") or (NWD_WinClass = "ATL:ScrapFrame"))) )
{
NWD_ImmediateDownRequest = 1
NWD_ImmediateDown = 0
NWD_PermitClick = 1
}
Else
{
NWD_ImmediateDownRequest = 0
NWD_ImmediateDown = 0
NWD_PermitClick = 1
}

NWD_Dragging := (NWD_WinClass != "Progman") and ((NWD_CtrlState = "D") or ((NWD_WinMinMax != 1) and !NWD_ImmediateDownRequest))

; checks wheter the window has a sizing border (WS_THICKFRAME)
If ( (NWD_CtrlState = "D") or (NWD_WinStyle & 0x40000) )
{
If ( (NWD_MouseStartX >= NWD_WinStartX + NWD_WinStartW / NWD_ResizeGrids) and (NWD_MouseStartX <= NWD_WinStartX + (NWD_ResizeGrids - 1) * NWD_WinStartW / NWD_ResizeGrids) )
NWD_ResizeX = 0
Else
If ( NWD_MouseStartX > NWD_WinStartX + NWD_WinStartW / 2 )
NWD_ResizeX := 1
Else
NWD_ResizeX := -1

If ( (NWD_MouseStartY >= NWD_WinStartY + NWD_WinStartH / NWD_ResizeGrids) and (NWD_MouseStartY <= NWD_WinStartY + (NWD_ResizeGrids - 1) * NWD_WinStartH / NWD_ResizeGrids) )
NWD_ResizeY = 0
Else
If ( NWD_MouseStartY > NWD_WinStartY + NWD_WinStartH / 2 )
NWD_ResizeY := 1
Else
NWD_ResizeY := -1
}
Else
{
NWD_ResizeX = 0
NWD_ResizeY = 0
}

If ( NWD_WinStartW and NWD_WinStartH )
NWD_WinStartAR := NWD_WinStartW / NWD_WinStartH
Else
NWD_WinStartAR = 0

; TODO : this is a workaround (checks for popup window) for the activation
; bug of AutoHotkey -> can be removed as soon as the known bug is fixed
If ( !((NWD_WinStyle & 0x80000000) and !(NWD_WinStyle & 0x4C0000)) )
IfWinNotActive, ahk_id %NWD_WinID%
WinActivate, ahk_id %NWD_WinID%

; TODO : the hotkeys must be enabled in the 2nd block because the 1st block
; activates them only for the first call (historical problem of AutoHotkey)
Hotkey, Shift, NWD_IgnoreKeyHandler
Hotkey, Ctrl, NWD_IgnoreKeyHandler
Hotkey, Alt, NWD_IgnoreKeyHandler
Hotkey, LWin, NWD_IgnoreKeyHandler
Hotkey, RWin, NWD_IgnoreKeyHandler
Hotkey, Shift, On
Hotkey, Ctrl, On
Hotkey, Alt, On
Hotkey, LWin, On
Hotkey, RWin, On
SetTimer, NWD_IgnoreKeyHandler, 100
SetTimer, NWD_WindowHandler, 10
}
Else
{
; this feature should be implemented by using a timer because
; AutoHotkeys threading blocks the first thread if another
; one is started (until the 2nd is stopped)

Thread, priority, 1
MouseClick, RIGHT, , , , , D
KeyWait, RButton
MouseClick, RIGHT, , , , , U
}
Return



Rob  
#2 Posted : Thursday, November 5, 2020 8:40:04 AM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 16 times
Was thanked: 174 time(s) in 151 post(s)
You can look at this thread, which allows for a similar style of resizing windows based on grids (though the mouse click sequence is slightly different):

https://forum.strokesplus.net/posts/t8252findunread-Scripting-help



Or, you can bind to the mouse button event and manually disable S+ while the left button is pressed down and enable when the left button is released.

Note that this will prevent you from using actions which have the Left mouse button as a modifier when pressed before the right button. This would also affect the rocker action of Left then Right button.
However, if you don't use those setups, this should work fine. I have not tested it much, though.

First, go to Options > Advanced and check the box for Enable Mouse Hook Event Subscription.

Then put this script in Global Actions > Load/Unload > Load (script):
Code:
//Only install this in the last script engine
if(__spEngineWrapper.Engine.Name == sp.EngineList().Last().Engine.Name)
{
    //This toggles on and off an asynchronous mouse button hook event subscription
    //If event already bound, disconnect
    var mouseButtonEventObj = sp.GetStoredObject("mouseButtonEvent");
    if(mouseButtonEventObj.GetType().FullName.includes('EventConnection'))
    {
        mouseButtonEventObj.disconnect();
        sp.DeleteStoredObject("mouseButtonEvent");
    } 
    else
    {
        //Otherwise, create the async event binding
        var mouseButtonEvent = MouseHook.OnMouseHookButtonEventAsync.connect(
            function (sender, mouseHookEvent) {
                //Wrap all code in try/catch, exceptions will crash S+
                try
                {
                    if(mouseHookEvent.Button == MouseButtons.Left)
                    {
                        if(mouseHookEvent.ButtonState == ButtonState.Down)
                        {
                            //Prevent S+ from reacting to mouse/keyboard events 
                            sp.DisableCapture();
                        }
                        else
                        {
                            //Allow S+ to react to mouse/keyboard events 
                            sp.EnableCapture();
                        }
                    }
                }
                catch {}
            });
        //Note that on S+ reload, events in Stored Object list have disconnect called on them
        sp.StoreObject("mouseButtonEvent", mouseButtonEvent);
    }
}

Edited by user Thursday, November 5, 2020 8:46:28 AM(UTC)  | Reason: Changed to only run in the last script engine

petercncn  
#3 Posted : Thursday, November 5, 2020 9:38:41 AM(UTC)
petercncn

Rank: Newbie

Reputation:

Groups: Approved
Joined: 11/4/2020(UTC)
Posts: 5
China

I put your code as you said to Global Actions > Load/Unload > Load (script), and my Autohotkey script works well with LEFT _BUTTON + RIGHT_BUTTON + DRAG.

Amazing!
Thank you very mush!
petercncn  
#4 Posted : Saturday, November 21, 2020 9:40:13 AM(UTC)
petercncn

Rank: Newbie

Reputation:

Groups: Approved
Joined: 11/4/2020(UTC)
Posts: 5
China

Now I also test your script in the link https://forum.strokesplu...ndunread-Scripting-help. The funtions in your scripts are also useful, but there is a confliction when I put the code you gave above in Global Actions > Load/Unload > Load (script)

I only want to disable S+ when the left button is pressed down first, then let other software get the hooks of left and right buttons.

And when the right button is pressed down first then Left pressed, I still want S+ to enable, saying that I want Left mouse button as a modifier (Capture Modifiers: After).

In short,
Left then Right button -- S+ should not work
Right then Left button -- S+ should work

Can you modify the code you gave above in Global Actions > Load/Unload > Load (script) to slove this problem?

Thank you very much.
Rob  
#5 Posted : Saturday, November 21, 2020 4:20:53 PM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 16 times
Was thanked: 174 time(s) in 151 post(s)
Quote:
In short,
Left then Right button -- S+ should not work
Right then Left button -- S+ should work


You would need to use a combination of the Right Click script and Release script to make this work.

In the Right Click event, you would set some variable, e.g.:
Code:
sp.StoreBool("rightDown", true);

And in Left Click use:
Code:
if(!sp.GetStoredBool("rightDown"))
{
    if(mouseHookEvent.Button == MouseButtons.Left)
    {
        {existing code}
    }
}

In Release:
Code:
if(click.Button == MouseButtons.Right) {
    sp.StoreBool("rightDown", false);
}
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.