Jump to content

AutoIT Toggle between two desktop apps - (Moved)


Mudoch
 Share

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 comment
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 comment
Share on other sites

Link to comment
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 comment
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 comment
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
 Share

×
×
  • Create New...