Using SplashImage as a per program macro legend

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Erik-the-Red
Posts: 2
Joined: 22 Sep 2022, 22:15

Using SplashImage as a per program macro legend

Post by Erik-the-Red » 22 Sep 2022, 22:28

Hello,

I have a script cobbled together that displays a different image depending on which window is active. I use this as a legend to show which macro keyboard shortcuts are active on the current focused window.

By and large I have it working, but the intended action is not reliable. If I focus on a window that's not listed in the various programs, the splashimage will deactivate, and won't come back up until I activate Excel again which is the first program in the stack.

If I comment out the other programs and just have one "WinwaitActive", it works flawlessly

Many thanks

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#Persistent
SetTitleMatchMode, 2

Goto Start

Start:
WinwaitActive, ahk_class XLMAIN
SplashImage, C:\Users\pretendUsername\AutoHotKey Scripts\GUI button layouts\Excel.jpg,A M B X-450 Y570, , , SplashImage , ,
WinWaitNotActive, ahk_class XLMAIN
SplashImage, Off 

WinwaitActive, docx ;WINWORD.exe
SplashImage, C:\Users\pretendUsername\AutoHotKey Scripts\GUI button layouts\Word.jpg,A M B X-450 Y570, , , SplashImage , ,
WinWaitNotActive, docx ;ahk_exe WINWORD.exe
SplashImage, Off 

WinwaitActive, ahk_exe acad.exe
SplashImage, C:\Users\pretendUsername\AutoHotKey Scripts\GUI button layouts\AutoCAD-Civil3D.jpg,A M B X-450 Y570, , , SplashImage , ,
WinWaitNotActive, ahk_exe acad.exe
SplashImage, Off 

WinwaitActive,  ahk_exe OUTLOOK.exe ;ahk_class rctrl_renwnd32;
SplashImage, C:\Users\pretendUsername\AutoHotKey Scripts\GUI button layouts\Outlook.jpg,A M B X-450 Y570, , , SplashImage , ,
WinWaitNotActive,  ahk_exe OUTLOOK.exe ;ahk_class rctrl_renwnd32
SplashImage, Off 

WinwaitActive, ahk_exe PDFXEdit.exe
SplashImage, C:\Users\pretendUsername\AutoHotKey Scripts\GUI button layouts\PDF XChange.jpg,A M B X-450 Y570, , , SplashImage , ,
WinWaitNotActive, ahk_exe PDFXEdit.exe
SplashImage, Off

#IfWinActive, ahk_exe Firefox.exe
SplashImage, C:\Users\pretendUsername\AutoHotKey Scripts\GUI button layouts\Firefox.jpg,A M B X-450 Y570, , , SplashImage , ,
WinWaitNotActive, ahk_exe Firefox.exe
SplashImage, Off

Goto Start

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Using SplashImage as a per program macro legend

Post by mikeyww » 23 Sep 2022, 05:33

Welcome to this AutoHotkey forum!

#If is not If. See the documentation.

WinWaitActive will wait forever until the window is active, unless you add a timeout. An alternative is to run a :arrow: SetTimer, get the active window's title (etc.), and then act accordingly.

Loop is generally preferred to "goto start"-- easier to stay out of trouble!

Another way is below.

Code: Select all

#SingleInstance Force
Loop {
 WinWaitNotActive, A
 WinGet, proc, ProcessName, A
 ToolTip, %proc%
 Switch proc {
  Case "firefox.exe": Send x
  Case "notepad.exe": Send y
 }
}
SplashImage is deprecated, so I would think about using Gui.

Erik-the-Red
Posts: 2
Joined: 22 Sep 2022, 22:15

Re: Using SplashImage as a per program macro legend

Post by Erik-the-Red » 26 Sep 2022, 16:31

Thank you. I'll give this a try and see how I go

Post Reply

Return to “Ask for Help (v1)”