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 9: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
Was thanked: 1 time(s) in 1 post(s)
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!
thanks 1 user thanked Holyman for this useful post.
soooulp on 4/24/2020(UTC)
Rob  
#2 Posted : Monday, November 11, 2019 10:01:16 PM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 28 times
Was thanked: 416 time(s) in 354 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/12/2019(UTC)
Rob  
#3 Posted : Monday, November 11, 2019 11:45:19 PM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 28 times
Was thanked: 416 time(s) in 354 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/12/2019(UTC)
Holyman  
#4 Posted : Tuesday, November 12, 2019 12:45:09 AM(UTC)
Holyman

Rank: Newbie

Reputation:

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

Thanks: 3 times
Was thanked: 1 time(s) in 1 post(s)
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 : Tuesday, November 12, 2019 1:37:23 AM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
You're very welcome!
thanks 1 user thanked Rob for this useful post.
Holyman on 11/12/2019(UTC)
lyscop  
#6 Posted : Friday, May 15, 2020 4:47:35 PM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Originally Posted by: lyscop Go to Quoted Post
Another suggestion:

It works perfectly when using a gesture to open a link in background.

And when I am not want to open the link, just want to open a new tab, it will jump to the end of the tab bar, how to open a new tab like open the link next to the current tab?


It is done.

I find a Chrome extension named Open New Tab HereOpen New Tab Here.

It will open a new tab next to the current tab, and it can be set as a shortcut, then replace the ctrl+t of the Open Link in New Tab script.
Whatsek  
#7 Posted : Monday, May 31, 2021 3:35:29 PM(UTC)
Whatsek

Rank: Newbie

Reputation:

Groups: Approved
Joined: 5/31/2021(UTC)
Posts: 2
Netherlands

Originally Posted by: Rob Go to Quoted Post
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); 


This was exactly what I was looking for after the extension "Long press new tab" was removed from the store.


Is there a tweak possible top open the new tab in the foreground?

I tried to edit the script to use CTRL+SHIFT+ENTER: "^+VK_RETURN" instead of: "^VK_RETURN" but it didnt work.
Gestures is ofcourse fine, but can also a long press be used?







asdf14  
#8 Posted : Thursday, June 10, 2021 1:50:15 AM(UTC)
asdf14

Rank: Newbie

Reputation:

Groups: Approved
Joined: 6/10/2021(UTC)
Posts: 5

Thanks: 4 times
Originally Posted by: Whatsek Go to Quoted Post
Originally Posted by: Rob Go to Quoted Post
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); 


This was exactly what I was looking for after the extension "Long press new tab" was removed from the store.


Is there a tweak possible top open the new tab in the foreground?

I tried to edit the script to use CTRL+SHIFT+ENTER: "^+VK_RETURN" instead of: "^VK_RETURN" but it didnt work.
Gestures is ofcourse fine, but can also a long press be used?









Try this.

Code:
sp.HideMouseCursor();
sp.MouseMove(action.Start);
sp.Sleep(30);
var c = sp.GetCurrentMouseCursor();
if(c == "Hand")
{
    sp.SendControlDown();
    sp.SendShiftDown();
    sp.MouseClick(action.Start, MouseButtons.Left, true, true);
    sp.MouseMove(action.End);
    sp.SendControlUp();
    sp.SendShiftUp();
}
else
{
    sp.MouseMove(action.End);
    sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_T]);
}
sp.ShowMouseCursor();
Whatsek  
#9 Posted : Monday, June 28, 2021 10:08:22 AM(UTC)
Whatsek

Rank: Newbie

Reputation:

Groups: Approved
Joined: 5/31/2021(UTC)
Posts: 2
Netherlands



Try this.

Code:
sp.HideMouseCursor();
sp.MouseMove(action.Start);
sp.Sleep(30);
var c = sp.GetCurrentMouseCursor();
if(c == "Hand")
{
    sp.SendControlDown();
    sp.SendShiftDown();
    sp.MouseClick(action.Start, MouseButtons.Left, true, true);
    sp.MouseMove(action.End);
    sp.SendControlUp();
    sp.SendShiftUp();
}
else
{
    sp.MouseMove(action.End);
    sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_T]);
}
sp.ShowMouseCursor();


Thank you, working perfectly!



mesersmith  
#10 Posted : Wednesday, November 2, 2022 2:19:47 PM(UTC)
mesersmith

Rank: Member

Reputation:

Groups: Approved
Joined: 2/8/2022(UTC)
Posts: 18
Romania
Location: calarasi

Thanks: 2 times
Originally Posted by: Rob Go to Quoted Post
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); 




Hi there!

Before in old SP i use this code:




-- this code does one of two things, if the mouse cursor
-- is a HAND, the link below the cursor is opened in a new
-- tab. If the mouse cursor is not a HAND, a new browser
-- tab is opened this action is executed by holding the
-- stroke button and clicking the left mouse button, either
-- over a link or anywhere over the browser for a new tab
--if acGetMouseCursorType() == "HAND" then
-- acMouseClick(gsx, gsy, 1, 1, 1)
--else
-- acSendKeys("^t")
--end


acConsumePhysicalInput(1) --prevent hand mouse movements from moving the mouse
acMouseMove(gsx, gsy) --move the cursor back to where the gesture began
acDelay(50) --pause briefly to allow the cursor to be drawn
if acGetMouseCursorType() == "HAND" then
acMouseClick(gsx, gsy, 1, 1, 1)
else
acSendKeys("^t")
end
acMouseMove(gex, gey) --move the mouse back to where the gesture ended
acConsumePhysicalInput(0) --allow input to behave as normal




Now i'm trying to use your new code, but i do something bad, because it opens new tab, but not link in new tab.
Please advice what and how to do.
mesersmith  
#11 Posted : Wednesday, November 2, 2022 2:37:37 PM(UTC)
mesersmith

Rank: Member

Reputation:

Groups: Approved
Joined: 2/8/2022(UTC)
Posts: 18
Romania
Location: calarasi

Thanks: 2 times
I figure it out.
Move on to next gesture that I have to bring here from old SP. :)
mesersmith  
#12 Posted : Monday, December 5, 2022 8:26:16 AM(UTC)
mesersmith

Rank: Member

Reputation:

Groups: Approved
Joined: 2/8/2022(UTC)
Posts: 18
Romania
Location: calarasi

Thanks: 2 times
Hi, Rob!

This code works if I do it on an empty space on a browser and opens a new tab and bring it in front.
If i make the same gesture but on an link, it opens the link but it stays on background, I mean it is not in front.



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);

Edited by user Monday, December 5, 2022 11:24:33 AM(UTC)  | Reason: Not specified

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.