0
votes

I am fairly new to the autohotkey program but I love the functionality of it all. I am looking to create a hotkey to open a program (if it's not already open) but it's open to activate the window. I've tried the below but it doesn't seem to work.

^+e::
#IfWinExist, ahk_class XLMAIN ahk_exe EXCEL.EXE
{
      WinActivate ahk_class XLMAIN ahk_exe EXCEL.EXE
}
return
#IfWinExist
#IfWinNotExist, ahk_class ahk_class XLMAIN ahk_exe EXCEL.EXE
{
run C:\Program Files\Microsoft Office\Office16\EXCEL.EXE
}
#IfWinNotExist
return

Also, could you confirm if mouse positions do not work on dual screen or windows 10?

Any help would be highly appreciated, thank you so much!

1
>"Also, could you confirm if mouse positions do not work on dual screen or windows 10?"< Ask that as a separate question; I have a bit of a longer answer for it and don't think it would be appropriate to tag it along to my answer for the first question. But tl;dr: yes, it is definitely possible in theory, but it takes a bit of effort to make it work in practiceSpyre

1 Answers

0
votes

Three things:

  1. I fixed the syntax and logic for the code. Please try to avoid using the #If statements (especially if you are new) as those tend to break scripts.
  2. Don't use both ahk_class and ahk_exe at the same time for IfWinActive, as that would be redundant (and nonfunctional as far as I am aware).
  3. Double check that the location of your EXCEL.EXE is where you say it is in your script (C:\Program Files\Microsoft Office\Office16\EXCEL.EXE), because on my computer it was located at C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE.

Here is the code that worked for me:

^+e::
IfWinExist, ahk_exe EXCEL.EXE
{
    WinActivate  ; Automatically uses the window found above.
    WinMaximize  ; same
    Send, Some text.{Enter}
    return
}else{
    run C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE
}
return