AutoHotkey Community

It is currently May 27th, 2012, 4:42 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 24 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: October 4th, 2009, 6:17 pm 
Offline

Joined: April 23rd, 2009, 11:01 pm
Posts: 13
Hello, I haven't used AutoHotkey in a while and was wondering how to do this:

I want to execute a script based on whether the "Google Search" button is pressed or if the "I'm Feeling Lucky" button is pressed on www.Google.com. I want to do this without using the image search command. (My real application is a little different, but if I figure out how to do this simple example, I will be able to expand on it)

Thanks for any help!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 4th, 2009, 7:10 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
there are 2 methods one involves parsing out the URL to see if you stay in the same domain. Based on your description tho this isnt what you need

The next option is much more complex and not for the feint of heart. I wont write you an example unless i get a comfirmation from you that you understand DOM very well events and either javascript or vbscript as my example will rely heavily on these principles andf im not inclined to teach you events or DOM
I will however show you how to capture an onclick event for a button using AHK

Please let me know for sure if this is worth myt effort or if your not readdy to learn something much more complicated

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 4th, 2009, 7:21 pm 
Offline

Joined: April 23rd, 2009, 11:01 pm
Posts: 13
Thanks for the reply tank. Yeah this may be more complicated than I anticipated. My real application is to detect a button press in an offline program, so the parsing of the domain name would not be a viable option. I'll probably read up on using Javascript with AutoHotkey to make this work. Thanks again.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 4th, 2009, 7:52 pm 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
I wanted to see if I could do this:
Code:
COM_Init() ; requires COM Standard Library
pwb := COM_CreateObject("InternetExplorer.Application")
COM_Invoke(pwb, "Visible", "True")
COM_Invoke(pwb, "Navigate", "www.google.com")
While, % COM_Invoke(pwb, "ReadyState") <> 4
   Sleep, 10

GS := COM_Invoke(pwb, "document.all.btnG")
IFL := COM_Invoke(pwb, "document.all.btnI")
sink1 := COM_ConnectObject(GS, "GS_")
sink2 := COM_ConnectObject(IFL, "IFL_"), done:=False
While(!done)
   Sleep, 10

; Cleanup
COM_DisconnectObject(sink1), COM_DisconnectObject(sink2)
COM_Release(pwb), COM_Release(GS), COM_Release(IFL), COM_Term()
Return


GS_OnClick() {
   SetTimer, Search, -10 ; EDIT - changed from GoSub per tank's recommendation below
}
IFL_OnClick() {
   SetTimer, Lucky, -10
}
Search:
   MsgBox, Google Search
   done:=True
   Return
Lucky:
   MsgBox, I'm Feeling Lucky
   done:=True
   Return

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Last edited by jethrow on October 4th, 2009, 8:21 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 4th, 2009, 7:59 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
is it active content such as a cd or something?
Using javascript via ahk is not any more straight forward than what i would propose and in fact may be a little more problematic
do you understand onclick events and DOM enuff to do this with javascript?
if so then this might be a road you want to persue

Code:
;------------------------------------------------------------------------------
; Requires COM.ahk Standard Library
; by Sean
; http://www.autohotkey.com/forum/topic22923.html
; Requires iWeb.ahk
; by tank
; http://www.autohotkey.com/forum/viewtopic.php?p=197475#197475
;------------------------------------------------------------------------------
/* written by tank to help with topic
http://www.autohotkey.com/forum/viewtopic.php?t=49594
Newbie, execute script based on webpage button press.
10/4/2009
*/
#Persistent
COM_CoInitialize()
OnExit,Close

If   pwb:=iWeb_getwin("google") {
   If   feel_lucky:=COM_Invoke(pwb,"document.all[btnI].")
      psink:=COM_ConnectObject(feel_lucky,"buttons_") ;buttons_ is a function prefix
   COM_Release(pwb)
}
Return

somecode:
{
   MsgBox some code to execute here
   Return
}

buttons_onClick()
{
   SetTimer,somecode,-10 ; do this to execute a thread this is the recommended method to execute some code
}

Close:
COM_CoUninitialize()
ExitApp

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 4th, 2009, 8:03 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
jethrow good work ( you posted before i did :twisted: ) but IMO
use
Code:
settimer,label,-10

events you wouldn't want the event to hold up the execution of the button while some code that may be lengthy executes. the page would not navigate till the event is done

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 4th, 2009, 8:06 pm 
Offline

Joined: April 23rd, 2009, 11:01 pm
Posts: 13
It's a program where my Mom writes her notes for work. The program has a lot of repetitive tasks and I told my Mom I would try to help her automate some of the stuff. Right now I have all the automated tasks as hotkeys, but I thought I could improve it by detecting when buttons are pressed and executing certain lines of the script.

I will have to do some research on the scripting you guys posted, it is all foreign to me.

Thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 4th, 2009, 8:07 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
Just to be clear
the code posted will ONLY work with a web page loaded in IE
Detecting a button in other programs is done totally differently and sometimes not at all

this also assumes that the application is not flash or java (java is different than JavaScript)

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2010, 3:27 am 
Offline

Joined: February 26th, 2009, 8:45 pm
Posts: 29
Thanks! Just what i was looking for! But the script only works for once. I mean, the second time that I press the "Search" Button for example, "SomeCode" doesn´t trigger. I´m looking kind of a steady-state. Every time that the seach button is pressed, execute some code. How can i achieve this?

Thanks again!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2010, 4:17 am 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
psink is destroyed with navigation upon a new load you would need to connect the object again

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 6th, 2010, 12:46 am 
Offline

Joined: February 26th, 2009, 8:45 pm
Posts: 29
Thanks again. I tried a lot, but i dont know how to control the flow of the script. What i want is that "somecode" executes every time an user clicks the button of a specific window(with a specific title of corse). This windows can be closed, opened and reloaded several times. Any suggestion?


Thanks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2010, 6:27 pm 
Offline

Joined: February 26th, 2009, 8:45 pm
Posts: 29
:? Any help?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2010, 11:40 pm 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
How about something like this?
Code:
#Persistent
SetTimer, ConnectGoogle, 100
Return

ConnectGoogle:
If WinExist( "Google - Windows Internet Explorer" ) {
   If Not pwb {
      pwb := IEGet( "Google - Windows Internet Explorer" )
      sink := COM_ConnectObject( doc:=pwb.document, "Doc_" )
      sink1 := COM_ConnectObject( doc.all.btnG, "GS_" )
      sink2 := COM_ConnectObject( doc.all.btnI, "IFL_" )
      done:=False
      While( !done )
         Sleep, 10
      GoSub, DisconnectGoogle
   }
} Else
   GoSub, DisconnectGoogle
Return

DisconnectGoogle:
   COM_DisconnectObject( sink ), COM_DisconnectObject( sink1 ), COM_DisconnectObject( sink2 ), pwb := ""
Return
Doc_OnReadyStateChange() {
   SetTimer, PageChange, -10
}
PageChange:
   While, pwb.ReadyState <> 4
      Sleep, 10
   done := True
Return
GS_OnClick() {
   SetTimer, Search, -10
}
IFL_OnClick() {
   SetTimer, Lucky, -10
}
Search:
   MsgBox, Google Search
   done:=True
Return
Lucky:
   MsgBox, I'm Feeling Lucky
   done:=True
Return

IEGet( Name="" ) {
   COM_Error( False )
   IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
   Name := Name="New Tab" ? "about:Tabs" : RegExReplace( Name," - (Windows|Microsoft) Internet Explorer" )
   Loop, % ( oShell := COM_CreateObject( "Shell.Application" ) ).Windows.Count
      If pweb := oShell.Windows( A_Index-1 )
         If ( pweb.LocationName=Name && InStr( pweb.FullName, "iexplore.exe" ) ) {
            COM_Error( True )
            Return, pweb
         }
}

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 9th, 2010, 3:56 am 
Offline

Joined: February 26th, 2009, 8:45 pm
Posts: 29
Thanks jethrow! I get an illegal character error message in line 9 in the "pwb.document" expression. What is this about?

Thanks again


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 9th, 2010, 3:58 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
I wrote this for AHKL & COM_L - see my signature.

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 24 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: 0x150||ISO, Bing [Bot], rbrtryn, Yahoo [Bot] and 65 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group