Jump to content

Is it possible to toggle between to different applications.


Go to solution Solved by ioa747,

Recommended Posts

Posted

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

 

Posted (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 by ioa747

I know that I know nothing

Posted (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 by MichaelCrawley
Posted (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 by MichaelCrawley
Posted

>"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()

Posted (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 by ioa747

I know that I know nothing

  • Moderators
Posted

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?

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.

Posted

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

 

  • Moderators
Posted

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.

  • Solution
Posted

 

#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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...