How to activate/deactivate AutoHotkey script based on active application (MS Excel)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Modaz
Posts: 5
Joined: 03 Aug 2021, 16:03

How to activate/deactivate AutoHotkey script based on active application (MS Excel)

03 Aug 2021, 16:22

Hello AHK experts,

I have basic programming experience, and I have been searching this for so long.

I am trying to make a script that works when MS Excel is active, and get back to the main script when I switch Excel window.

I ended up having two separate scripts and keep switching between them manually every time I switch into/outfrom Excel window, which feels stupid and painful. any help?

PS: I've seen this post on Stack Overflow (https://tinyurl.com/stackoverflowAutoSwitch) , but couldn't make it fit my needs with my basic AHK skills.
Modaz
Posts: 5
Joined: 03 Aug 2021, 16:03

Re: How to activate/deactivate AutoHotkey script based on active application (MS Excel)

06 Aug 2021, 09:39

Nope!

I'm using that (#IfWinActive/WinWaitActive) in both my scripts (the main and the Excel's). but this is not what I'm looking for.

Because of conflicting hotkeys reasons, I need to have the scripts alternating when window changes. instead of doing them manually every time I AltTab.
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: How to activate/deactivate AutoHotkey script based on active application (MS Excel)

06 Aug 2021, 09:47

Combine the scripts into one. You can then add conditional statements so that the right routine executes according to the active window.
Modaz
Posts: 5
Joined: 03 Aug 2021, 16:03

Re: How to activate/deactivate AutoHotkey script based on active application (MS Excel)

06 Aug 2021, 17:01

Thank you Andrew for your responses.
However, this didn't work with me and it kept conflicting despite the Conditional IFs.

Since you insist in embedding both. does that mean there is no way that we can switch between two alternating scripts?

As in:
Detect window
If Window active
Run script
Suspend
and the same in the other script?
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: How to activate/deactivate AutoHotkey script based on active application (MS Excel)

06 Aug 2021, 17:14

I'm not in a position to insist on anything. Forum readers just offer suggestions, examples, information, and ideas. I offered an idea that I thought could resolve your issue. Sure, one script can run another. It seems like extra work, but it can be done. Feel free to post yours if you like, so that readers can give you more specific guidance and troubleshooting based on your specific scripts.

In addition to running another script, a script can send or receive a message originating from a script.

Explained: https://www.autohotkey.com/docs/commands/OnMessage.htm

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Rohwedder, ruespe and 361 guests