vmicchia Posted January 30, 2012 Share Posted January 30, 2012 Hi there. I have this programand what I want for it to do is if there is an IE window open it will check the URL and then if it is a specific URL it will move the window to the opposite monitor and allow it to remain the focus. If the URL changes it sends it back to the second monitor and makes another program the focus and otherwise just makes the second program the focus. The problem is that if I chage IE windows I have to activate the window twice before it checks the URL again. The program that is usally in focus is what changes the IE windows. Here's the code: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase $Form1 = GUICreate("DMFocusKeeper", 117, 191, 192, 124,0x00000008) $Button1 = GUICtrlCreateButton("Start", 20, 72, 75, 25) $Button3 = GUICtrlCreateButton("Close", 20, 116, 75, 25) $Label1 = GUICtrlCreateLabel("Eterm Focus Keeper", 8, 32, 100, 20, BitOR($SS_CENTER,$SS_CENTERIMAGE)) $var=0 $screen = 0 GUISetState(@SW_SHOW) While 1 $msg=GUIGetMsg() Select Case $msg=$gui_event_close Exit Case $msg=$Button3 Exit Case $msg=$Button1 CheckActive() Case Else Sleep(10) EndSelect WEnd Func CheckActive() If $var=1 Then GUICtrlSetData($Button1,"Start") $var=0 Else GUICtrlSetData($Button1,"Stop") $var=1 EndIf While $var = 1 $msg=GUIGetMsg() Select Case $msg=$gui_event_close Exit Case $msg=$Button3 Exit Case $msg=$Button1 CheckActive() Case Else Sleep(10) IF WinActive("[CLASS:IEFrame]") Then Sleep(10) send ("!d") send ("^c") $link = ClipGet() IF $link == "http://www.google.com/" AND $screen <> 1 Then send ("#+{RIGHT}") $screen = 1 ElseIf $link <> "http://www.google.com/" AND $screen == 1 Then send ("#+{LEFT}") $screen = 0; WinActivate ("Eterm") Else WinActivate ("Eterm") EndIf EndIf EndSelect WEnd EndFunc Link to comment Share on other sites More sharing options...
Bert Posted January 30, 2012 Share Posted January 30, 2012 You may want to look at IE.au3. It is in the helpfile The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
vmicchia Posted January 30, 2012 Author Share Posted January 30, 2012 I was looking at those. I'm not sure that they would help though. I am opening the IE tabs from the Eterm program that my program sets to active not from the program I wrote. I may have missed some thing but those only seem to work when opened from the autoit program. Link to comment Share on other sites More sharing options...
vmicchia Posted January 30, 2012 Author Share Posted January 30, 2012 Ok I've changed my code a bit. I know the switch statements are odd but I was having some issues with the if else statements for some reason. Anyway my problem now is that I want the program running constatly to check for these things but if I leave IE as the active window it runs this code constantly Send("!d") Send("^c") $link = ClipGet() I for some reason can't think of a way to loop that to fix the problem and I can't find a function to check a change in active window or anything like that. Any help would be much appreciated. Here's the whole code now: expandcollapse popup#region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker #endregion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase $Form1 = GUICreate("DMFocusKeeper", 117, 191, 192, 124, 0x00000008) $Button1 = GUICtrlCreateButton("Start", 20, 72, 75, 25) $Button3 = GUICtrlCreateButton("Close", 20, 116, 75, 25) $Label1 = GUICtrlCreateLabel("Eterm Focus Keeper", 8, 32, 100, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE)) If Not IsDeclared("screen") Then $screen = 0 EndIf $var = 0 GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $gui_event_close Exit Case $msg = $Button3 Exit Case $msg = $Button1 CheckActive() Case Else Sleep(10) EndSelect WEnd Func CheckActive() If $var = 1 Then GUICtrlSetData($Button1, "Start") $var = 0 Else GUICtrlSetData($Button1, "Stop") $var = 1 EndIf While $var = 1 $msg = GUIGetMsg() Select Case $msg = $gui_event_close Exit Case $msg = $Button3 Exit Case $msg = $Button1 CheckActive() Case Else Sleep(10) If WinActive("[CLASS:IEFrame]") Then Send("!d") Send("^c") $link = ClipGet() Switch $link Case [url="http://www.google.com"]http://www.google.com[/url] Switch $screen Case 0 Send("#+{RIGHT}") $screen = 1 EndSwitch Case Else Switch $screen Case 1 Send("#+{LEFT}") $screen = 0 WinActivate("Eterm") EndSwitch EndSwitch EndIf EndSelect WEnd EndFunc ;==>CheckActive Link to comment Share on other sites More sharing options...
vmicchia Posted January 31, 2012 Author Share Posted January 31, 2012 ALright, I've been playing around with the code all day. I've almost got it but I seem to be having one last problem. When I run the program for some reason I have to activate it twice to get this line to fire : If $title == "MyWindow - Windows Internet Explorer" And $screen <> 1 Then All the rest of the code works fine. But that being the most important line dosen't work for some reason. Here is the whole code: expandcollapse popup#region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker #endregion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase $Form1 = GUICreate("DMFocusKeeper", 117, 191, 192, 124, 0x00000008) $Button1 = GUICtrlCreateButton("Start", 20, 72, 75, 25) $Button3 = GUICtrlCreateButton("Close", 20, 116, 75, 25) $Label1 = GUICtrlCreateLabel("Eterm Focus Keeper", 8, 32, 100, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE)) If Not IsDeclared("screen") Then $screen = 0 EndIf $var = 0 GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $gui_event_close Exit Case $msg = $Button3 Exit Case $msg = $Button1 CheckActive() Case Else Sleep(10) EndSelect WEnd Func CheckActive() If $var = 1 Then GUICtrlSetData($Button1, "Start") $var = 0 Else GUICtrlSetData($Button1, "Stop") $var = 1 EndIf While $var = 1 $msg = GUIGetMsg() Select Case $msg = $gui_event_close Exit Case $msg = $Button3 Exit Case $msg = $Button1 CheckActive() Case Else If WinActive("[CLASS:IEFrame]") Then $title = WinGetTitle("[CLASS:IEFrame]", "") If $title == "MyWindow - Windows Internet Explorer" And $screen <> 1 Then $screen = 1 Send("#+{RIGHT}") ;MsgBox(1, "Ths is the screen variable", $screen) ElseIf $title <> "MyWindow- Windows Internet Explorer" And $screen == 1 Then $screen = 0 Send("#+{LEFT}") ;MsgBox(1, "Ths is the screen variable", $screen) WinActivate("Eterm") ElseIf $title <> "MyWindow - Windows Internet Explorer" And $screen <> 1 Then WinActivate("Eterm") $screen = 0 ElseIf $title <> "MyWindow - Windows Internet Explorer" And $screen == 1 Then $screen = 1 EndIf EndIf EndSelect WEnd EndFunc ;==>CheckActive Link to comment Share on other sites More sharing options...
BrewManNH Posted January 31, 2012 Share Posted January 31, 2012 For one thing, never use "==" unless you're doing a string to string comparison and you want to check using a case sensitive search mode. Other than that, it should work. vmicchia 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
vmicchia Posted January 31, 2012 Author Share Posted January 31, 2012 I figured it out. I needed to add a Sleep() before checking the page title. It was taking a second or so to load so it was getting the old title. Also thank you for the tip BrewManNH. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now