MichaelCrawley Posted February 27 Share Posted February 27 So I have toggle function that I use to toggle between web pages noted below. If I want to toggle between and excel file and a web page Is it possible in AutIT? I looked in the Libary and I am not sure what I need to look for if you could point in that directio it would be helpful. Func Toggle() ;==>Toggle between web pages ConsoleWrite('@@ (8) :(' & @MIN & ':' & @SEC & ') Toggle()' & @CR) ;### Trace Function Static $bFirst = True WinActivate(@SW_MAXIMIZE) If $bFirst Then Send("^1") Else Send("^2") EndIf $bFirst = Not $bFirst EndFunc Link to comment Share on other sites More sharing options...
ioa747 Posted February 27 Share Posted February 27 (edited) Func Toggle($hWin1, $hWin2) ;==>Toggle between web pages ConsoleWrite('@@ (8) :(' & @MIN & ':' & @SEC & ') Toggle()' & @CR) ;### Trace Function Static $bFirst = True If $bFirst Then If WinExists($hWin1) Then WinActivate($hWin1) Send("^1") Else MsgBox(0, 'Toggle @error:', "$hWin1 not exist" ) EndIf Else If WinExists($hWin2) Then WinActivate($hWin2) Send("^2") Else MsgBox(0, 'Toggle @error:', "$hWin2 not exist" ) EndIf EndIf $bFirst = Not $bFirst EndFunc ;==>Toggle Edited February 27 by ioa747 MichaelCrawley 1 I know that I know nothing Link to comment Share on other sites More sharing options...
MichaelCrawley Posted February 27 Author Share Posted February 27 (edited) @ioa747That doesn't look near as intimidating as I thought it would be thank you! So you pretty much use the toggle same way. You put a message box if there an error Winactive is used activate excel or the the browser for the toggle. is there anything else im missing? Edited February 27 by MichaelCrawley Link to comment Share on other sites More sharing options...
ioa747 Posted February 27 Share Posted February 27 test only I know that I know nothing Link to comment Share on other sites More sharing options...
MichaelCrawley Posted February 27 Author Share Posted February 27 @ioa747 Correct that will get me started where I want to go.... I can work though the rest. ioa747 1 Link to comment Share on other sites More sharing options...
MichaelCrawley Posted February 28 Author Share Posted February 28 (edited) I hope you don't mind me tagging you on this. @ioa747 I may be getting something wrong or modified the solution and broke it. But I am not getting an error on the toggle. The toggle work but the screen dont switch or toggle between each other. Func Toggle($webPage, $openExcel) ;==>Toggle between web pages ConsoleWrite('@@ (8) :(' & @MIN & ':' & @SEC & ') Toggle($webPage, $openExcel)' & @CR) ;### Trace Function Static $bFirst = True If $bFirst Then If WinExists($webPage) Then WinActivate($webPage) Send("^1") Else MsgBox(0, 'Toggle @error:', "$webPage not exist" ) EndIf Else If WinExists($openExcel) Then WinActivate($openExcel) Send("^2") Else MsgBox(0, 'Toggle @error:', "$openExcel not exist" ) EndIf EndIf $bFirst = Not $bFirst EndFunc ;==>Toggle The files open without issue.... This is my excel file that opens ;Function to check to see if excel is open Func OpenExcel() ;looks for the process excel.exe if it is open then prompt file is alreday open If ProcessExists ("excel.exe") Then msgbox($MB_SYSTEMMODAL, "", "File is Already Open") else ;If is is not open it will open the fuction for excel Run('"C:\Program Files (x86)\Microsoft Office\Office16\excel.exe" "C:\Users\mcrawley\Desktop\this file.xlsm", @SW_MAXIMIZE') EndIf EndFunc This does open my web page ;function to open webpage Func webPage() Run ('"C:\Program Files\Google\Chrome\Application\chrome.exe" https://docs.google.com/spreadsheets/IChangedTheName --start-fullscreen') Sleep(5000) EndFunc ;==> open webpages Edited February 28 by MichaelCrawley Link to comment Share on other sites More sharing options...
MichaelCrawley Posted February 28 Author Share Posted February 28 >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /test /run /prod /ErrorStdOut /in "C:\Users\mcrawley\Documents\testScript\evap6_Switch.au3" /UserParams +>13:37:07 Starting AutoIt3Wrapper (21.316.1639.1) from:SciTE.exe (4.4.6.0) Keyboard:00000409 OS:WIN_10/2009 CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper - *** Compile in Test mode skipping Tidy; Au3Stripper; Resource updating and Versioning to speed up the process. *** >Running AU3Check (3.3.16.1) from:C:\Program Files (x86)\AutoIt3 input:C:\Users\mcrawley\Documents\testScript\evap6_Switch.au3 +>13:37:07 AU3Check ended.rc:0 >Running:(3.3.16.1):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\mcrawley\Documents\testScript\evap6_Switch.au3" +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop. @@ (8) :(37:17) Toggle() Link to comment Share on other sites More sharing options...
ioa747 Posted February 28 Share Posted February 28 (edited) What triggers the change? (the Toggle). What do you want to achieve? Edit: explanation I see the function that opened the website I see the function that opened xl I see the toggle function but I don't see when and how you call the toggle function and as a second thought to explain what you want to achieve since you're dealing with Excel maybe you don't need to go back and forth between windows if you use #include <Excel.au3> Edited February 28 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 28 Moderators Share Posted February 28 Watch your quotes, I didn't really read through the post, I just happened to catch this: ;If is is not open it will open the fuction for excel Run('"C:\Program Files (x86)\Microsoft Office\Office16\excel.exe" "C:\Users\mcrawley\Desktop\this file.xlsm", @SW_MAXIMIZE') Should be more like: ;If is is not open it will open the fuction for excel Run('"C:\Program Files (x86)\Microsoft Office\Office16\excel.exe" "C:\Users\mcrawley\Desktop\this file.xlsm"', @SW_MAXIMIZE) No? MichaelCrawley 1 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
MichaelCrawley Posted February 29 Author Share Posted February 29 I have a loop that runs and in the loop a button that call excels and the web page ; Loop until the user exits. $closeApp = True While 1 Switch GUIGetMsg() ;cases for QCDM Case $idButton_QCDM ;Calls excel file to open openExcel() ;open webpage webPage() Sleep(1000) ; Calls the Toggle for the two open files Toggle($openExcel, $webPage) ;Cawse to Closes Chrome from button Case $idButton_CLOSEQCDM ;Closes Chrome WinClose("EVAP 6 e-QCDM Hamilton - Google Sheets - Google Chrome","") exitChrome() ;Caset to close excel and chrome Case $idButton_Exit oExcel() Terminate() EndSwitch WEnd Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 29 Moderators Share Posted February 29 Try waiting a bit for the window to be active if you're going to use Send() keys. WinActivate() + WinWaitActive() + Sleep(relative time until it works) + then action aka Send(keys) If you're unaware, there are excel udfs and browser udfs that would/could eliminate the need to use Send() (never been a fan of sending open keys to my computer, I like being program specific, like ControlSend() or the udfs I mentioned). The way you're doing it, the keys are being sent as soon as you're using WinActivate(). That's like expecting a teenager to get out of bed and get ready the first time you tell them to get up. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
MichaelCrawley Posted February 29 Author Share Posted February 29 @SmOke_N I love the reference to Teens... dead on. Okay thank you I will give that a try. Link to comment Share on other sites More sharing options...
Solution ioa747 Posted March 1 Solution Share Posted March 1 expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ; first make 2 example File ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Global $sFile_1 = @ScriptDir & '\Test_1.txt' Global $sFile_2 = @ScriptDir & '\Test_2.txt' If Not FileExists($sFile_1) Then FileWriteLine($sFile_1, "Test_1") If Not FileExists($sFile_2) Then FileWriteLine($sFile_2, "Test_2") ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; handle of the $hWnd1 window. ShellExecute($sFile_1) ;, "", "", "", @SW_MAXIMIZE) Local $hWnd1 = WinWaitActive("Test_1.txt", "", 3) If Not WinExists("Test_1.txt") Then Exit ConsoleWrite("$hWin1 not exist & Exit" & @CRLF) ; handle of the $hWnd2 window. ShellExecute($sFile_2) ;, "", "", "", @SW_MAXIMIZE) Local $hWnd2 = WinWaitActive("Test_2.txt", "", 3) If Not WinExists("Test_1.txt") Then Exit ConsoleWrite("$hWin2 not exist & Exit" & @CRLF) For $i = 1 To 20 Toggle($hWnd1, $hWnd2) Sleep(50) Send("{END}") Send("{ENTER}") Send("Test line " & $i) Next ;-------------------------------------------------------------------------------------------------------------------------------- Func Toggle($hWin1, $hWin2) ;==>Toggle between web pages ;~ ConsoleWrite('@@ (8) :(' & @MIN & ':' & @SEC & ') Toggle()' & @CR) ;### Trace Function Static $bFirst = True If $bFirst Then If WinExists($hWin1) Then WinActivate($hWin1) Else MsgBox(0, 'Toggle @error:', "$hWin1 not exist") EndIf Else If WinExists($hWin2) Then WinActivate($hWin2) Else MsgBox(0, 'Toggle @error:', "$hWin2 not exist") EndIf EndIf $bFirst = Not $bFirst EndFunc ;==>Toggle ;-------------------------------------------------------------------------------------------------------------------------------- I know that I know nothing Link to comment Share on other sites More sharing options...
MichaelCrawley Posted March 7 Author Share Posted March 7 @ioa747 I have not tested this I think the will be much cleaner thank you!!! ioa747 1 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