troubleshooting Question

Writing AutoHotkey scripts for a series of IF queries

Avatar of WeThotUWasAToad
WeThotUWasAToad asked on
ChromeMicrosoft ExcelVisual Basic ClassicAutoHotkeyMicrosoft Office
5 Comments1 Solution24 ViewsLast Modified:
Hello,

What is the general format or syntax for writing a series of IF queries in AutoHotkey?

I'm very familiar with the syntax for doing the same thing in Excel. For example:

=
IF(CriteriaA,ActionA,
IF(CriteriaB,ActionB,
IF(CriteriaC,ActionC,
IF(CriteriaD,ActionD,
"`"))))

In the above formula, once a particular Criteria is found to be true, the corresponding Action is executed and the formula stops. If none of the Criteria are true, the formula sends a backtick ("`").

Note: I am a quadriplegic with paralyzed hands. As a result, I have AHK scripts written for almost every conceivable action and generally have several hundred of them, each with its own hotkey, running at the same time. That creates the problem of having and remembering a large number of hotkeys.

What I would like to do is, for a given Hotkey, set up multiple Actions with the Action being executed dependent on which window is active.

So for example, let's say the Hotkey is F2, the script would look something like this (I know the following is not a real script but hopefully it conveys what I am after):

F2::
SetTitleMatchMode, 2
IfWinActive, Excel
   {
   GoSub, ExecuteActionsA
   }
IfWinActive, PowerPoint
   {
   GoSub, ExecuteActionsB
   }
IfWinActive, Chrome
   {
   GoSub, ExecuteActionsC
   }
IfWinActive, RingCentral
   {
   GoSub, ExecuteActionsB
   }
Return

In this way, and assuming I can get a given Hotkey's script to stop once it finds the active window, I could have a single hotkey trigger multiple different macros depending simply on which window is currently active.

Thanks
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros