Jump to content

AutoIT Toggle between two desktop apps - (Moved)


Recommended Posts

I need to replace a desktop applications functionality. I'll call it App "A".

The application has defined 2 hot keys one that toggles between it and another window, App "B", and one that triggers keystrokes to App "B" to get data where App "A" can access it. Then tells app "A" to fire off processing of data.. Unfortunately when App "B" is a 64bit application this functionality no longer works. 

 

For now I've hobbled together a work a round solution by using 2 apps with what appears to be similar abilities. AutoIt and a desktop application that allows me to define the 2 hot keys. The SutoItX Dll is great for my processes within App "A" as it uses VBA for event driven tasks.

The second app allows me to define the Hot keys and which windows they belong to.

My fail is on how to use AutoIT to define the hot Keys and link to specific windows.

So as I see this working:

          App "A" launches and fires off internal VBA code that in turn sets up HotKeys. If App "B" is not found code shuts down without enabling the hotkeys.  

          A hot key of CTRL-F1 toggles, activates window, back and forth between App "A and "B"  So the hotkey is captured only when either App "A" or "B" is currently the active focus. and swaps the active focus application window.

          A hot key of CTRL-F2 from App "B", Send Key strokes to App "B" to place App "B" windows' content into windows clip board then switch to App "A" and send a keystroke, CTRL-F3, to trigger processing the clip board through App "A"'s normal event handlers.  App "A" already knows that CTRL-F3 means to run custom VBA code to process the clipboard.

Any help would be appreciated here, thanks.  

Link to post
Share on other sites
  • Moderators

Moved to the appropriate forum.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

What have you tried so far ?  You seem to have done some tests with AutoIt.  Please post the code you have so far, and tell us where you have issues.

Link to post
Share on other sites

Actually as far as a Hotkey functionality with AutoIt I've done nothing as I don't seem to find anything helpful as a simple sample.  

The product I work with has default "Hotkeys" that allow the program to toggle between apps and also to trigger a VBA event that allows us to ingest data to pass on to the main program. The product and the connectivity tool they use are built as 32bit solutions and do not recognize 64 bit applications. The vendor has told me at this time they have no plans of implementing a 64bit connectivity module for Windows applications.

As I said the problem is Windows 10 and bit-ness of desktop applications.  If the application is 64bit the Hotkey simply posts to the window the actual key and not toggle windows or trigger the VBA event.

My time constraints did not allow me much time, less than an hour to be honest, to resolve the problem. So when I found both AutoIt and another program that offer the HotKey element it was the fix I needed. AutoIt had both needs a HotKey and the ability to replace SendKeys in VBA, the other application seemed to only offer HotKey tooling.

I quickly got AutoIt Dll working for the data return, found plenty of samples, but I could not find how to use AutoIt for the desktop hot key functionality the samples I found what seemed to be all kinds of things mostly too complex for my needs and difficult to break down with the time constraint. With the other hotkey app I found there was plenty on the desktop hotkey samples but nothing on VBA integration, it does not seem to be available.

Now I have a bit of time, off the clock, to step back and try to figure out how to do the HotKey toggle and sending of keystrokes through AutoIt. The goal being to reduce long term support needs and overhead of multiple applications installed and running on a system.

For simple reasons I'll use Chrome and Notepad++ as the 2 apps I'm toggling between and Notepad++ as the main app I want to send a keystroke to activate a Menu option in.

Here is the other tools script that allows this to work. I removed obvious references to that hotkey program from the script. The script is loaded with the other app through Windows C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup folder entry.

;IF Numpad+ switch to Notepad++, push Ctrl{F1} to Notepad++
#ifwinactive class Chrome_WidgetWin_1
Numpadadd::
winactivate, class Notepad++
sendinput, ^{F1}
return

;If = key toggle beween Chrome and Notepad++
#ifwinactive class Chrome_WidgetWin_1
=::
winactivate, class Notepad++
return

#ifwinactive class Notepad++
=::
winactivate, class Chrome_WidgetWin_1
return

Any help is most appreciated, thanks.

Link to post
Share on other sites

Well after an entire day digging I found enough on this subject and created a working solution.

So since I wanted to avoid extra configuration outside the solution I now Launch AutoIt from within my VBA application to enable the toggle and processing trigger.

The VBA does the heavy work, though AutoItX, to verify the Windows exist before launching the main script passing 2 parameters of the windows(apps) I want to control.

Here is the script:

;AutoIt v3.x script for control of two Apps in windows 10
;Equals(=) toggles between apps only
;Num Pad Add key toggles from Host1 to Host2 and starts processing data in Clipboard

;Created by Larry Sall Jan 2020.
;Windows are defined and checked in VBA then passed here as params

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

$cmdparms = $CmdLine[0]
if $cmdparms > 1 Then

    ;Define our windows
    $sHost1_Win = $CmdLine[1]
    $sHost2_Win = $CmdLine[2]

    ;Insert our HotKeys
    HotKeySet("{=}", "ToggleWin")
    HotKeySet("!{ESC}", "Terminate") ;Alt{ESC}
    HotKeySet("{NUMPADADD}", "Host1Run")

    ;Stay in Memory and run
    While 1 
        Sleep(100)
    WEnd
Else
    MsgBox($MB_SYSTEMMODAL,"App Window Error","Missing required parameters")
EndIf

Func ToggleWin()
   if winactive($sHost1_Win) then
      if winexists($sHost2_Win) Then
         Winactivate($sHost2_Win)
      EndIf
   ElseIf Winactive($sHost2_Win) Then
      if WinExists($sHost1_Win) Then
         WinActivate($sHost1_Win)
      EndIf
   Else ;allow normal keystroke in any other window
      HotKeySet("{=}")
      send("=")
      HotKeySet("{=}", "ToggleWin")
   endif
EndFunc

Func Terminate()
    Exit 0
EndFunc

Func Host1Run()
   if WinActive($sHost2_Win) Then
       WinActivate($sHost1_Win)
       Send("^{F1}")
   Else ;allow normal functionality in any other window
      HotKeySet("{NUMPADADD}")
      Send("{NUMPADADD}")
      HotKeySet("{NUMPADADD}", "Host1Run")
   EndIf
 EndFunc

Not sure if this is best way but it works.

Link to post
Share on other sites

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.

  • Similar Content

    • By HoratioCaine
      Hi, everyone.
      I have python code for kill window,  but sometimes it does not working .

      My code is :
      import subprocess import time import ctypes au3_dll = ctypes.windll.LoadLibrary(r'D:\AutoIt\AutoItX3.dll') def close_ie(title): subprocess.Popen(f"C:/Program Files (x86)/Internet Explorer/iexplore.exe https://cn.bing.com/?mkt=zh-CN") time.sleep(2) au3_dll.AU3_Opt("WinTitleMatchMode", 2) ret = au3_dll.AU3_WinKill(title, "") print(ret) if __name__ == '__main__': title = '必应 - Internet Explorer' for i in range(10): close_ie(title) My expectation is that all IE windows will be closed, but there will always be a few windows still there.
      My env: win10 64bit python3.6.4 autoit v3.3.14.2  
      Any suggestions would be appreciated 
    • By learner123
      Hi All,
       
      I am new to this AUTO IT and I have created a script that will open an app,enter pin and copy the code generated to clipboard. My java code call this autoIT script and use the copied generated code from clipboard.
      This works fine when server  window is on focus. My server is an windows server. 
      But when I minimize or disconnect the server, the script opens the app.exe but doesn't copy any value to clipboard.  
      Can anyone help me on this 😐
       
      Run("C:\Program Files (x86)\RSA SecurID Software Token\SecurID.exe")
      Local $hWnd=WinWait("abc - RSA SecurID Token") ; waits until the window is the active window
      $hWin = WinGetHandle("abc - RSA SecurID Token");
      ControlSend($hWnd,"","","1111") ; simulates pressing the Home key
      ControlSend($hWnd,"","","{ENTER}");
      ControlSend($hWnd,"","","^c");
      Sleep(1000) ;
      ControlSend($hWnd,"","","^c");
       
    • By poddex
      Hello everyone.
      I always try to work with old Windows 10 versions as much as possible because I know mane compatibility issues with Windows 10 upgrading. 
      But I couldn't do anything else (I got drivers problem), and nothing couldn't help me besides upgrading, so I upgraded from 1807 to 1903.
      And...get another problem 😃
      I use AutoitX library in external project like this.
      ObjectAutoIt=New COMObject("AutoItX3.Control");
      ObjectAutoIt.AutoItSetOption("WinTextMatchMode",2);
              While ObjectAutoit.WinExists("",WindowHeader) Cycle 
                  ObjectAutoIt.WinClose("",WindowHeader);
              EndCycle;
      After upgrade I get that this line code 
      While ObjectAutoit.WinExists("",WindowHeader)
      become extremely low - ~ 20 seconds even if 10 windows open. But before upgrade it takes 0.5 s for a max.
      And every time that this code line passes through  - it takes ~20s, (20.115, for example), not less, not more. Something pauses it to work.
      How can I diagnose, what is that?
      I tried reinstall whole AutoIt, but no results.
      Thanks to all.
    • By AnonymousX
      Hello,
      I'm trying to be able to switch back and forth between multiple excel spreadsheets and I can't seem to get the WinActivate function to work, and bring the desired window the be the active window.
      Could I please get some assistance, I've tried a few things and nothing seems to work quite right. Below is a test case where I'm just trying to make the first excel sheet that was opened become the active window, and testing it by grabbing a cell value off that workbook. The message box produces the correct answer if both files are closed before running but the 2nd test file will appear to be the active window. If the code is run again without closing the excel files, nothing works (file does not appear to be active and message box will not give an answer).
       
      #include <Excel.au3> Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase ;Open Test1 Excel Workbook local $oExcel = _Excel_open() Local $ofile = @ScriptDir & "\test1.xlsx" Local $oWorkbook = _Excel_BookOpen($oExcel,$ofile) ;Open Test2 Excel Workbook local $mExcel = _Excel_open() Local $mfile = @ScriptDir & "\test2.xlsx" Local $mWorkbook = _Excel_BookOpen($mExcel,$mfile) ; This workbook is completely blank WinActivate($oWorkbook); should make Test1 the active window local $read1 = _Excel_RangeRead($oWorkbook,Default,"B2"); Cell B1 in Test1 workbook contains the word Test MsgBox(0,0,$read1);Should returns the word test  
    • By PramodR
      I see couple of ways to import module ,  one with specifying absolute path of the file to get imported, by this logic i believe to import a specific module will be like #include <c:\modulepath\duplicatemodule.au3>
      but i see some registry changes also made in this link , can someone explain why that registry change is really required.
       
×
×
  • Create New...