Jump to content
Mudoch

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.  

Share this post


Link to post
Share on other sites

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

 

Share this post


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.

Share this post


Link to post
Share on other sites

Melba23, like your tag line.   I'm in the mindset of "Old enough to know better, young enough to not worry"

Share this post


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.

Share this post


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

  • Similar Content

    • 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.
       
    • By PramodR
      I am trying to execute a exe file in auto it as elevated previlage , but not successful till now . below are the methods i tried till now.
      Disabled UAC access from windows and  selected run only as administrator from executable properties.  i logged in as administrator but still exe needs to launch as run as administrator.
       
      Used Below methods from forum still no luck. anything i missing? i tried to use powershell.ps1 intead of exe as well.
      1.  Local $iPID = RunAs($sUserName, @ComputerName, $sPassword, $RUN_LOGON_NOPROFILE, "c:\Exec.exe", "", @SW_SHOWMAXIMIZED)
      2.  RunWait("C:\Automation\TestScripts\Writefilter.exe", @WindowsDir, @SW_MAXIMIZE)     - Std out error
       
      This command gives out put as running with admin rights
      #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #RequireAdmin Example() Func Example()     ; Change the username and password to the appropriate values for your system.     Local $sUserName = "Admin"     Local $sPassword = "PASSWORD"     Local $iPID = RunAs($sUserName, @ComputerName, $sPassword, 0, "noetpad.exe", "", @SW_SHOWMAXIMIZED)     ; Run Notepad with the window maximized. Notepad is run under the user previously specified. ;~     RunWait(@WindowsDir & "C:\automation\TestScripts\Writefilter.exe", @WindowsDir, @SW_MAXIMIZE) EndFunc   
    • By PramodR
      Hello,
      I have below code which execute well when all prerequisite met, when window pop up is not available its throwing an error. i want to capture error instead of error  out.
      error handling added in the code to capture it but it does not work still giving me error saying Variable must be of type "Object".
      $oCurWin.FindAll($treescope_subtree, $oCondition, $pElements)
      $oCurWin^ ERROR
      How to catch error properly . 
       
       
    • By PramodR
      Hello,
      I have to execute below block of code in elevated previllage, as that particular wmic class will work only with admin previlage.
      i am getting out put when i launch autoit as administrator,  but i will not be able to launch autoit as admin in this particular case but my user have admin rights.
      is there any better way i can run those command as administrator.?
      tried below steps:
      i have tried #RequireAdmin but that creates a user prompt  Tried using Runas command but gives error as wrong username or password , stuck with that step.  
       
×
×
  • Create New...