Author Topic: Open Link In New Tab  (Read 1978 times)

0 Members and 1 Guest are viewing this topic.

SteveB69

  • Contributor
  • ***
  • Posts: 72
  • Karma: -1
    • View Profile
Open Link In New Tab
« on: December 14, 2015, 08:50:25 AM »
I'm trying to create a command to open a new chrome tab from wherever my mouse is.

So I have currently set up VC to
Window.Focus - Chrome
Mouse.Right Click
InputKeys.Send - Down
InputKeys.Send - Enter
However what this is doing is opening the link in the same tab & keeping the right click contect menu on screen.

I've also tried using the mouse move relative option & whilst the right click contect menu appears in the right place it just does the same, opens in same tab.

Any clues?
Chances are I've searched the forum, searched the wiki & scoured You Tube but I'm just to thick to work it out without help!

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Open Link In New Tab
« Reply #1 on: December 14, 2015, 08:57:24 AM »
The easiest way to open a new tab is to use the keyboard shortcut Ctrl-T.

This post about controlling the Chrome browser should help.

http://voxcommando.com/forum/index.php?topic=811.msg9679#msg9679

In the future, you can just post the command xml to share your actual command with us. That saves a lot of time for everyone -- particularly for cases when we might need to test a command to see what's happening.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Open Link In New Tab
« Reply #2 on: December 14, 2015, 09:00:29 AM »
A more basic example:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.0.9-->
<command id="628" name="Chrome new tab" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Window.Focus</cmdType>
    <params>
      <param>chrome</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>SendKeys</cmdType>
    <params>
      <param>^t</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>Chrome new tab</phrase>
</command>
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

SteveB69

  • Contributor
  • ***
  • Posts: 72
  • Karma: -1
    • View Profile
Re: Open Link In New Tab
« Reply #3 on: December 14, 2015, 09:11:29 AM »
Thanks for the quick replies, I can already open a new blank tab via Ctrl & T but I want VC to open a link in a new tab for which there is no keyboard shortcut, cos it depends of course what link you want to open in a new tab.
So by putting my mouse over the link & saying Open In New Tab is what I am trying to do??

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.0.7-->
<command id="-1" name="Actions copied from LCB">
  <action>
    <cmdType>Window.Focus</cmdType>
    <params>
      <param>chrome</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Mouse.RightClick</cmdType>
    <params />
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Mouse.MoveRelative</cmdType>
    <params>
      <param>5,5</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Mouse.LeftClick</cmdType>
    <params />
    <cmdRepeat>1</cmdRepeat>
  </action>
</command>

One other thing, is it possible VC is running the script to fast, is there a way to insert a pause?
« Last Edit: December 14, 2015, 09:28:13 AM by SteveB69 »
Chances are I've searched the forum, searched the wiki & scoured You Tube but I'm just to thick to work it out without help!

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Open Link In New Tab
« Reply #4 on: December 14, 2015, 09:30:53 AM »
Thanks for clarifying and for posting your command.

This method for clicking on a link and opening a new tab (in Chrome, specifically) is probably more reliable.

To put code in a code box on the forum, click the # symbol.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.0.9-->
<command id="-1" name="Click on link" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="" loopMax="" description="">
  <action>
    <cmdType>Window.Focus</cmdType>
    <params>
      <param>chrome</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>InputKeys.KeysDown</cmdType>
    <params>
      <param>{LCONTROL}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Mouse.LeftClick</cmdType>
    <params />
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>InputKeys.KeysUp</cmdType>
    <params>
      <param>{LCONTROL}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>SendKeys</cmdType>
    <params>
      <param>^{TAB}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>Click on link</phrase>
</command>

[Edited xml above: VC.Pause not needed]

Your technique for this command might also work, but it doesn't look as though you're using the mouse-relative coordinates correctly. 5 pixels by 5 pixels is not likely to be correct.
« Last Edit: December 14, 2015, 09:41:39 AM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

SteveB69

  • Contributor
  • ***
  • Posts: 72
  • Karma: -1
    • View Profile
Re: Open Link In New Tab
« Reply #5 on: December 14, 2015, 09:45:22 AM »
Thanks for the above help, slowly getting there.

I see what you mean abouyt the relative pixels, problem is that the link one wants to open appears in different places, I thought the mouse relative command was to work from wherever the mouse cursor is positioned.

I'm now finding that the command will sometimes work & other times it will just move the mouse position?
The VC.Pause doesn't seem to have made any difference?

*************************************
Is there a windows focus command for right click context menus?
« Last Edit: December 14, 2015, 09:55:01 AM by SteveB69 »
Chances are I've searched the forum, searched the wiki & scoured You Tube but I'm just to thick to work it out without help!

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Open Link In New Tab
« Reply #6 on: December 14, 2015, 10:09:14 AM »
Yes, the action Mouse.MoveRelative will move relative to the original position of your mouse pointer, but you were moving it down 5 pixels and to the right 5 pixels and I'm not sure if that will always make sense or not.

It is not important though because nime5ter gave you a working command that does not use the mouse movement and so should be more reliable.  Did you try it?  We have tested it here and it works perfectly every time.

It is unlikely that the pause is required, it would only be necessary if, for some reason the right-click context menu in chrome took a while to appear.  If that is the case, it might be necessary to increase the delay to a higher value.  Remeber that pause uses milliseconds. 

No, there is no such thing as focus for a context menu, nor is there any need for it.  In fact in this case you don't even need the focus at the beginning of the command because by clicking the link with mouse emulation it will automatically focus chrome.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Open Link In New Tab
« Reply #7 on: December 14, 2015, 10:16:47 AM »
If you really want to use relative mouse movement, this command works reliably for me, however by design chrome will open the new tab but focus will remain on the current tab.  If you want to switch to the new tab you will then need to add the keyboard emulation for Ctrl-Tab which is what nime5ter did in the command she created for you.

Note: I am not using any focus action in this command since it is not needed.  I am using a pause of 200 milliseconds which works fine on my machine.  If your machine is slow to display the context menu you might need to increase this value, but be careful because if you increase it too much there is a chance that you will physically move the mouse during that time which would break the command.  A 3rd option would be to open the context menu and then emulate the keys for DOWN and then ENTER but all of these options are overkill when you can use the Ctrl-Click method.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.1.1-->
<command id="-1" name="open in new tab" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="" loopMax="" description="">
  <action>
    <cmdType>Mouse.RightClick</cmdType>
    <params />
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Mouse.MoveRelative</cmdType>
    <params>
      <param>9,9</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>VC.Pause</cmdType>
    <params>
      <param>200</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Mouse.LeftClick</cmdType>
    <params />
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>open in new tab</phrase>
</command>