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

Notification

Icon
Error

Options
Go to last post Go to first unread
Holyman  
#1 Posted : Monday, November 11, 2019 2:10:33 PM(UTC)
Holyman

Rank: Newbie

Reputation:

Groups: Approved
Joined: 11/11/2019(UTC)
Posts: 2
Russian Federation
Location: St. Petersbourg

Thanks: 3 times
Dear Rob,
I need your help to write script, which opens links in new browser's tab.
I think it will become relevant for many people.
I am not a programmer, an approximate algorithm is given under the spoiler.
With Great respect, John Cool




Thank YOU!
Rob  
#2 Posted : Monday, November 11, 2019 3:01:16 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 506
United States

Thanks: 5 times
Was thanked: 99 time(s) in 86 post(s)
Hi and welcome!

So this would be an almost literal conversion (I added 2 sleep calls to prevent things from being executed too fast):
Code:
var open_link_in_background = false;

action.Window.Activate();
sp.ConsumePhysicalInput(true);

var clicked = false;
var i = action.Start.Y; //action.Start is a Point, with .X and .Y properties
var i_end = i + 6;

while(i < i_end) {
    sp.MouseMove(new Point(action.Start.X, i));
    sp.Sleep(20);
    if(sp.GetCurrentMouseCursor() == "Hand") {
        if(!clicked) {  //You could also use - if(clicked == false) - "!" is the same "not"
            if(open_link_in_background) {
                sp.MouseClick(new Point(action.Start.X, i), MouseButtons.Middle, true, true); 
            } else {
                sp.SendControlDown();
                sp.Sleep(20);
                sp.MouseClick(new Point(action.Start.X, i), MouseButtons.Left, true, true); 
                sp.SendControlUp();
            }
            clicked = true;
        }
    }
    i = i + 2;
}

sp.ConsumePhysicalInput(false);
sp.MouseMove(action.End); //action.End is also a Point


This would be the same, just refactored to reduce unnecessary code lines, allow three loop passes which seems to be the intent ("<= 6" - less than or equal to 6), and change the "i" to "Y" so it's more clear what the variable is for:
Code:
var open_link_in_background = false;

sp.ConsumePhysicalInput(true);

for(var Y = action.Start.Y; Y <= action.Start.Y + 6; Y += 2) {
    sp.MouseMove(new Point(action.Start.X, Y));
    sp.Sleep(20);
    if(sp.GetCurrentMouseCursor() == "Hand") {
        if(open_link_in_background) {
            sp.MouseClick(new Point(action.Start.X, Y), MouseButtons.Middle, true, true); 
        } else {
            sp.SendControlDown();
            sp.Sleep(20);
            sp.MouseClick(new Point(action.Start.X, Y), MouseButtons.Left, true, true); 
            sp.SendControlUp();
        }
        break; //Stop looping
    }
}

sp.ConsumePhysicalInput(false);
sp.MouseMove(action.End); 
thanks 1 user thanked Rob for this useful post.
Holyman on 11/11/2019(UTC)
Rob  
#3 Posted : Monday, November 11, 2019 4:45:19 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 506
United States

Thanks: 5 times
Was thanked: 99 time(s) in 86 post(s)
Oops! I forgot your Ctrl+T part of the script, also added some extra delay after the control down call, again to allow time for the key event to be recognized (on my PC, anyway)

Code:
var open_link_in_background = false;
var clicked = false;

sp.ConsumePhysicalInput(true);

for(var Y = action.Start.Y; Y <= action.Start.Y + 6; Y += 2) {
    sp.MouseMove(new Point(action.Start.X, Y));
    sp.Sleep(20);
    if(sp.GetCurrentMouseCursor() == "Hand") {
        if(open_link_in_background) {
            sp.MouseClick(new Point(action.Start.X, Y), MouseButtons.Middle, true, true); 
        } else {
            sp.SendControlDown();
            sp.Sleep(100);
            sp.MouseClick(new Point(action.Start.X, Y), MouseButtons.Left, true, true); 
            sp.SendControlUp();
        }
        clicked = true;
        break; //Stop looping
    }
}

if(!clicked) {
    sp.SendKeys("^t");  // Send CTRL+T keystroke
}

sp.ConsumePhysicalInput(false);
sp.MouseMove(action.End); 
thanks 1 user thanked Rob for this useful post.
Holyman on 11/11/2019(UTC)
Holyman  
#4 Posted : Monday, November 11, 2019 5:45:09 PM(UTC)
Holyman

Rank: Newbie

Reputation:

Groups: Approved
Joined: 11/11/2019(UTC)
Posts: 2
Russian Federation
Location: St. Petersbourg

Thanks: 3 times
Originally Posted by: Rob Go to Quoted Post
Oops!I forgot your Ctrl T part of the script

Yes! I also noticed this, I’m breaking my brain for an hour where to insert this Ctrl+I! I appreciate your time and don't want to bother you for such trifles, and i was very happy when you wrote the answer!
Because i transferred all the gestures from the old version of your wonderful program, this is the only gesture that i can' be transfer! Now it works PERFECTLY!!!
Love Thank you so much, dear Rob! Love

Rob  
#5 Posted : Monday, November 11, 2019 6:37:23 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 506
United States

Thanks: 5 times
Was thanked: 99 time(s) in 86 post(s)
You're very welcome!
thanks 1 user thanked Rob for this useful post.
Holyman on 11/12/2019(UTC)
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.