Jump to content

Recommended Posts

Posted (edited)

Hi all

 

Imagine this scenario:

Firefox is running and is the active window,

the clipboard has a URL that we wish the browser to navigate to,

and now we need Firefox to initiate the "Paste and Go" MenuItem - which will do that.

 

Instead of sending a RightClick, and then moving with the Arrow Keys to appropriate MenuItem, and then simulating en [Enter],

maybe there's a way to spare this part, and initiate that MenuItem via a Windows Message?

 

I tried using Spy++ to find such a message, but couldn't.

There are 2 possibilities here:

1) There isn't such a Windows Message that is Sent for that MenuItem

2) There is a Windows Message that is Sent for that MenuItem, but I am just not finding it

 

Can anyone please try and see if he gets any success with that?

 

If this is not possible,

might there be another way which I could make Firefox navigate to a URL (which is in the Clipboard, or in a Variable),

other than the above mentioned way, and without installing a plugin?

 

Thank you

Edited by Zohar
  • Zohar changed the title to In Firefox, Is it Possible to Initiate the the "Paste and Go" MenuItem via a Windows Message?
Posted

Thank you ioa747

That's actually what I currently use
(or to be more accurate, I use Ctrl-L instead of F6, since it's more reliable)
Yet this way is problematic:
If the page is slow, it affects the time it takes the F6/Ctrl-L focus to happen.

That's why I wish to use the "Paste and Go" menuItem,
but hopefully, without opening it and selecting the MenuItem,
and instead, activating it via a SendMessage()..
(if one exists.. and that's where I need help)

 

 

Posted

An approach based on UIAutomation :

; From Nine
#include <Constants.au3>
#include "CUIAutomation2.au3"

Opt("MustDeclareVars", True)

Global Const $SELFLAG_TAKEFOCUS = 1

ClipPut("www.google.com") ;  for testing purposes

Example()

Func Example()
  If Not ClipGet() Then Return SetError(1) ; clip empty

  Local $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation)

  Local $pDesktop, $pCondition, $pChrome, $pBarView, $pAddress, $sText, $pPathValue
  $oUIAutomation.GetRootElement($pDesktop)
  Local $oDesktop = ObjCreateInterface($pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)

  $oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "Chrome_WidgetWin_1", $pCondition)
  $oDesktop.FindFirst($TreeScope_Descendants, $pCondition, $pChrome)
  Local $oChrome = ObjCreateInterface($pChrome, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
  If Not IsObj($oChrome) Then Return SetError(2) ; chrome not started

  $oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "LocationBarView", $pCondition)
  $oChrome.FindFirst($TreeScope_Descendants, $pCondition, $pBarView)
  Local $oBarView = ObjCreateInterface($pBarView, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)

  $oUIAutomation.CreatePropertyCondition($UIA_ControlTypePropertyId, $UIA_EditControlTypeId, $pCondition)
  $oBarView.FindFirst($TreeScope_Descendants, $pCondition, $pAddress)
  Local $oAddress = ObjCreateInterface($pAddress, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)

  $oAddress.GetCurrentPropertyValue($UIA_ValueValuePropertyId, $sText)
  ConsoleWrite("Current Address = " & $sText & @CRLF)

  $oAddress.GetCurrentPattern($UIA_LegacyIAccessiblePatternId, $pPathValue)
  Local $oPathValue = ObjCreateInterface($pPathValue, $sIID_IUIAutomationLegacyIAccessiblePattern, $dtagIUIAutomationLegacyIAccessiblePattern)
  $oPathValue.SetValue(ClipGet())
  $oPathValue.Select($SELFLAG_TAKEFOCUS)

  WinActivate("[CLASS:Chrome_WidgetWin_1]")
  WinWaitActive("[CLASS:Chrome_WidgetWin_1]")
  Sleep(500)
  Send("{ENTER}")
EndFunc   ;==>Example

 

Posted

KaFu:

Thank you very much.

I indeed considered using the Command Line,
but knew that it will open a new tab each time, and for that reason didn't go that way.

I need to re-use the existing tab..


Nine:

Thank you for this solution.

Does UIAutomation require any addon to be installed on Firefox, for communicating with the browser?

Posted

Thank you very much Nine.

Do you know how this UDF makes Firefox navigate to a URL?
After all, If we use AutoIt Window Info Tool on Firefox,
we cannot see any controls, since Firefox is using some custom drawing library of their own..

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...