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

Notification

Icon
Error

Options
Go to last post Go to first unread
sdqdlwq  
#1 Posted : Wednesday, April 28, 2021 5:32:02 PM(UTC)
sdqdlwq

Rank: Newbie

Reputation:

Groups: Approved
Joined: 8/17/2020(UTC)
Posts: 8

Hi Rob, Thank you very much for developing both StrokesPlus and StrokesPlus.net, they are excellent.
I have been using StrokesPlus for almost two years and this year I am going to move to StrokesPlus.net.
In StrokesPlus I have set up a script (1) that
acMouseClick(gsx,gsy,0,1,1)
acDelay(50)
acSendKeys("t")
acMouseMove(gex,gey)
In browsers Chrome and FireFox, I can open links or call Google Translate for web translation, depending on the starting point of the gesture.
So in StrokesPlus.net I have set up a script (2) based on script (1).
sp.Sleep(100);
sp.MouseClick(action.Start, MouseButtons.Right, true, true)
sp.Sleep(50);
sp.SendKeys("t");
Now the problem is that after I switch the primary and secondary buttons in Windows System - Mouse Properties.
Code (1) still works fine in StrokePlus.
But code (2) does not work in StrokesPlus.net.

My English is very poor, I hope you can read my question, thanks!
Rob  
#2 Posted : Wednesday, April 28, 2021 7:00:02 PM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 21 times
Was thanked: 265 time(s) in 231 post(s)
In S+.net, the MouseButtons class is using Windows' values, which is handling the button swap, treating Right as Left and Left as Right.

The code below will check to see if the mouse buttons are swapped, and change the button used during the click accordingly.
Code:
// See here for more details: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsystemmetrics
var SM_SWAPBUTTON = 23;
var mouseButtonsSwapped = sp.GetSystemMetricsByIndex(SM_SWAPBUTTON);

sp.Sleep(100);
sp.MouseClick(action.Start, mouseButtonsSwapped ? MouseButtons.Left : MouseButtons.Right, true, true)
sp.Sleep(50);
sp.SendKeys("t");
sdqdlwq  
#3 Posted : Thursday, April 29, 2021 4:17:41 PM(UTC)
sdqdlwq

Rank: Newbie

Reputation:

Groups: Approved
Joined: 8/17/2020(UTC)
Posts: 8

Hello Rob.
Thank you very much for your prompt reply in your busy schedule.
sp.MouseClick() has been bothering me for a long time because I don't know computer programming and am not a native English speaker.
The code you replied yesterday solved my problem perfectly.
Although I haven't really understood the implications, I'm now trying to teach myself some programming basics to better use S+.net.
To relieve the fatigue of using the mouse with one hand, I now often alternate between using the mouse with my left and right hand.
To do this I set up a script in S+.net that switches between the primary and secondary mouse buttons:

// Toggle mouse primary and secondary buttons
sp.Sleep(100);
sp.SendKeys("^%+s"); // This group of shortcut keys brings up the Mouse Settings window
sp.Sleep(100);
sp.SendKeys("s");
sp.Sleep(20);
sp.SendKeys("{ENTER}");

Now I have two requests and suggestions.
1. Is it possible to add a few lines of code to this script so that after executing this script (after switching the primary and secondary buttons on a windows system), S+.net can automatically recognize the changes made to the system regarding the primary and secondary buttons?
2. Or in the future add a function in S+.net options to automatically identify whether the windows system has switched between primary and secondary buttons?
-- Although there are not many cases like mine where I often use the mouse alternately with my left and right hands.
The above, I am using the software for English translation, hope you can read it, thank you!

Sincere regards.
sdqdlwq  
#4 Posted : Thursday, April 29, 2021 4:38:20 PM(UTC)
sdqdlwq

Rank: Newbie

Reputation:

Groups: Approved
Joined: 8/17/2020(UTC)
Posts: 8

Also, you can find many tutorials and scripts for StrokesPlus on Chinese sites, but very few tutorials and scripts for StrokesPlus.net.
-- and there are a few Chinese tutorials that mislead S+net beginners, such as the sp.RunProgram() function, which wasted a lot of my time because of some inaccurate Chinese tutorial.
It wasn't until after carefully reading the contents of the script help and searching the web that I really understood the parameters in the function.
So although it crashes from time to time while using S+, there are still a lot of Chinese mouse gesture enthusiasts who have not moved to the more advanced S+net.

I have over 300 gesture scripts set up in S+, most of which have been migrated to S+net and are running very smoothly.
Currently in the process of moving from S+ to S+net, there is only one type of script left to rewrite, which is a challenge for me. Please help me rewrite it into S+net code so that I can later adapt other scripts myself based on this template.
-- I know this request is excessive and will waste your valuable time. If you are busy now, then you can help rewrite it later when you have time, or I can make an effort to look up the information myself.
The code in S+ is as follows.

acSetClipboardText("") // clip.Clear();
acDelay(50) // sp.Sleep(100);
acSendKeys("^c") //sp.Sleep(100);
// The following part of the code conversion was a challenge for me
local key=acGetClipboardText()
local isUrl=string.find(key,"www.")
if isUrl==nil then
isUrl=string.find(key,".com")
end
if isUrl==nil then
key=string.gsub(key,"%s","%%20")
key="http://cn.bing.com/search?q="..key;
end
acDelay(100) // sp.Sleep(100);
acRunProgram("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",key,0, 1)


thanks
Rob  
#5 Posted : Thursday, April 29, 2021 5:02:25 PM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 21 times
Was thanked: 265 time(s) in 231 post(s)
For the mouse swap, use these.

Global Actions > Load/Unload > Load (script)
Code:
if(!NativeModules.MouseSwap)
{
    var Int32T = host.typeOf(clr.System.Int32);
    var BooleanT = host.typeOf(clr.System.Boolean);
    
    var mouseSwapTB = sp.NativeModule().DefineType(
        "MouseSwap", 
        "Class,Public,SequentialLayout,Serializable"
    );

    mouseSwapTB.DefinePInvokeMethod(
        "SystemParametersInfo",
        "user32.dll",
        [Int32T,Int32T,Int32T,Int32T], 
        Int32T, 
        "PreserveSig"
    );
    mouseSwapTB.Create();
}

function SwapMouseButtons() {
    var SM_SWAPBUTTON = 23;
    var SPIF_SENDCHANGE = 0x0002;
    var SPI_SETMOUSEBUTTONSWAP =0x0021;
    var mouseSwapped = sp.GetSystemMetricsByIndex(SM_SWAPBUTTON);
    NativeModules.MouseSwap.SystemParametersInfo(SPI_SETMOUSEBUTTONSWAP, mouseSwapped ? 0 : 1, 0, SPIF_SENDCHANGE);
}

function MouseClick(pt, btn, down, up) {
    var SM_SWAPBUTTON = 23;
    var mouseSwapped = sp.GetSystemMetricsByIndex(SM_SWAPBUTTON);
    if(mouseSwapped) {
        if(btn === MouseButtons.Left) {
            btn =  MouseButtons.Right;
        } else if(btn === MouseButtons.Right) {
            btn =  MouseButtons.Left;
        }
    }
    sp.MouseClick(pt, btn, down, up);
}

Instead of your script to swap mouse buttons, just call this function instead (defined above) - this swaps buttons without having to open the mouse settings window.
Code:
SwapMouseButtons();

Then instead of sp.MouseClick just use MouseClick (function defined above) which has the logic of checking the state of the swapped mouse buttons and converts automatically.
Code:
sp.Sleep(100);
MouseClick(action.Start, MouseButtons.Right, true, true);  // <-- Notice: no "sp." just MouseClick
sp.Sleep(50);
sp.SendKeys("t");

Edited by user Thursday, April 29, 2021 5:30:18 PM(UTC)  | Reason: Not specified

Rob  
#6 Posted : Thursday, April 29, 2021 5:15:25 PM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 21 times
Was thanked: 265 time(s) in 231 post(s)
For clipboard website/search:
Code:
try
{
    // No need to clear the clipboard, that is a heavy command
    sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_C]);
    sp.Sleep(100);
    var key = clip.GetText();
    // If www. or .com exists in copy, build URL
    if(key.includes("www.") || key.includes(".com")) {
        if(!key.startsWith("http")) {
            key = "http://" + key;
        }
    } else {
        // Otherwise, format text for URL parameter
        key = encodeURIComponent(key);
        key = "http://cn.bing.com/search?q=" + key;
    }
    // Open default browser
    sp.Run(key);

    // Or could use this instead to directly open Chrome
    // sp.RunProgram("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", key, "open", "normal", false, false, false);
} 
catch(err) {
    sp.MessageBox(`Error: ${err.message}`, "Error");
}
sdqdlwq  
#7 Posted : Friday, April 30, 2021 12:42:28 PM(UTC)
sdqdlwq

Rank: Newbie

Reputation:

Groups: Approved
Joined: 8/17/2020(UTC)
Posts: 8

Hello Rob.
Thank you very much for your generous help.
The scripts you have written are great and work well to avoid unknown shortcut key conflicts.
I have tested these scripts on S+net and they work very well.
I have now completed the transfer of the scripts from S+ to S+net.
I will add the above scripts with Chinese descriptions and introduce them to Chinese users of S+net.
I hope more and more mouse gesture fans will use S+net.
Thanks again.
Rob  
#8 Posted : Friday, April 30, 2021 1:01:25 PM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 21 times
Was thanked: 265 time(s) in 231 post(s)
You are welcome!

In the next update of S+ I'm going to update sp.MouseClick so it uses the specified mouse button even if mouse buttons are swapped.

I simply forgot about that when I was writing S+.net.
sdqdlwq  
#9 Posted : Friday, April 30, 2021 1:32:02 PM(UTC)
sdqdlwq

Rank: Newbie

Reputation:

Groups: Approved
Joined: 8/17/2020(UTC)
Posts: 8

Rewrite sp.MouseClick(),of course it's good that there is no need to add a global script in "Global Actions > Load/Unload > Load (script)".
In this way, the function of using SwapMouseButtons() alone to switch between primary and secondary mouse buttons is also disabled.
Then is there a script that does not use shortcut key combinations to pop up mouse properties and switch between primary and secondary mouse buttons?
sdqdlwq  
#10 Posted : Friday, April 30, 2021 1:41:24 PM(UTC)
sdqdlwq

Rank: Newbie

Reputation:

Groups: Approved
Joined: 8/17/2020(UTC)
Posts: 8

I used to set the following code in StrokePlus.
acDelay(50)
acShellExecute("open", "C:\StrokesPlus-lnk\mouse.lnk","","",1)
acSendKeys("{DELAY=50}s{ENTER}")
acDelay(50)
acDisplayText("Mouse.lnk S+Enter", "Arial",60,0,200,255,500,gsx,gsy)
But it didn't work?
In this case, I'll try sp.RunProgram() in S+net to see if it works.
sdqdlwq  
#11 Posted : Friday, April 30, 2021 2:34:25 PM(UTC)
sdqdlwq

Rank: Newbie

Reputation:

Groups: Approved
Joined: 8/17/2020(UTC)
Posts: 8

Sorry, just tested it and the above code works in S+, it just gets stuck sometimes.
So, it should work in S+net as well.
Or just put the global code you wrote in the "mouse primary and secondary button switch" script.
I remember that it took a while to write this code in S+, including using acRunProgram/ main.cpl and other methods
Finally, I chose the -set shortcut -mouse properties... The way to do it.
Please forgive me for using software for English translation, the expression is not very clear.
Sorry for the delay.
Thank you.
sdqdlwq  
#12 Posted : Friday, April 30, 2021 3:55:17 PM(UTC)
sdqdlwq

Rank: Newbie

Reputation:

Groups: Approved
Joined: 8/17/2020(UTC)
Posts: 8

Toggle mouse primary and secondary buttons script.
Code:
sp.Sleep(100)
sp.RunProgram("C:\\Windows\\System32\\main.cpl", "", "", "normal", true, false, false);
sp.Sleep(100);
sp.SendKeys("s");
sp.Sleep(20);
sp.SendKeys("{ENTER}");
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.