Opening Just One Instance Of Calculator

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
NalaEdaw
Posts: 27
Joined: 15 Mar 2023, 14:30

Opening Just One Instance Of Calculator

Post by NalaEdaw » 14 Jan 2024, 04:08

I used to be able to open just one instance of Calculator using the code below. I dont know if the latest dev build of Windows 11 broke something but now it dosnt work, just keeps open multiple instances.
The code I used to use is:

Code: Select all

Alt & F4:: {
 If WinExist('ahk_exe ApplicationFrameHost.exe')
  WinActivate
 Else Run 'calc'
}
I have also tried

Code: Select all

Alt & F4:: {
 If WinExist('calculator ahk_exe ApplicationFrameHost.exe')
  WinActivate
 Else Run 'calc'
}
And

A

Code: Select all

lt & F4:: {
 If WinExist('ahk_exe calc.exe')
  WinActivate
 Else Run 'calc'
}
but cannot get it to work now.
Is there something obvious that I am doing wrong?

Thanks in advance for any help.

MysticDude
Posts: 15
Joined: 02 Jan 2020, 05:32

Re: Opening Just One Instance Of Calculator

Post by MysticDude » 14 Jan 2024, 05:12

Your first code is working for me in both 10 and 11 (not dev build). Did anything change when you look at the calculator with window spy?

My guess is there is another ApplicationFrameHost conflicting. For the title, try this:

Code: Select all

WinExist('Calculator ahk_class ApplicationFrameWindow ahk_exe ApplicationFrameHost.exe')
Make sure calculator has a capital C, it is case sensitive.

NalaEdaw
Posts: 27
Joined: 15 Mar 2023, 14:30

Re: Opening Just One Instance Of Calculator

Post by NalaEdaw » 14 Jan 2024, 14:14

Thanks for the help but sadly it didnt work, I couldnt open Calculator with it. I will try Window Spy but to be honest not sure what to do with it.

MysticDude
Posts: 15
Joined: 02 Jan 2020, 05:32

Re: Opening Just One Instance Of Calculator

Post by MysticDude » 15 Jan 2024, 19:02

Window Spy will tell you exactly what the title/class/exe is. If that changed for some reason in the latest dev build, you can identify what it is.

To use it, run any AHK script, right click the script's tray icon > Window Spy.

TomBombadil
Posts: 5
Joined: 01 Jan 2024, 12:22

Re: Opening Just One Instance Of Calculator

Post by TomBombadil » 16 Jan 2024, 17:40

I believe, I did post previously what you are looking for here: viewtopic.php?f=83&t=124462

User avatar
boiler
Posts: 17242
Joined: 21 Dec 2014, 02:44

Re: Opening Just One Instance Of Calculator

Post by boiler » 16 Jan 2024, 19:06

Yeah, but the issue isn't the structure of his code, but rather what the actual WinTitle information for the Calc application is in his version of Windows.

coffee
Posts: 133
Joined: 01 Apr 2017, 07:55

Re: Opening Just One Instance Of Calculator

Post by coffee » 17 Jan 2024, 14:23

I believe that to cover all bases you have to do something like:

Code: Select all

; assuming titlematchmode 2
winID := WinExist("ahk_exe calc.exe") || WinExist("Calculator ahk_exe ApplicationFrameHost.exe")
At some point it was just ApplicationFrameHost.exe, on my current environment it can also be detected by CalculatorApp.exe
edit: nevermind, CalculatorApp.exe yields a different window ID, even though it's still calculator.

Also, initial post is using combination keys to hook onto alt + f4, instead of !F4. Not sure if that may be part of the issue depending on what other hotkeys are in the script.
However, the first code box in OP runs fine on my end with nothing else conflicting.

NalaEdaw
Posts: 27
Joined: 15 Mar 2023, 14:30

Re: Opening Just One Instance Of Calculator

Post by NalaEdaw » 17 Jan 2024, 15:31

Thankyou all for reading and trying to help.

@coffee I am not sure I fully understand how to use your script but this is what I have that will open Calculator but wont stop at one instance.

Code: Select all

Alt & F4:: {
 ; assuming titlematchmode 2
winID := WinExist("ahk_exe calc.exe") || WinExist("Calculator ahk_exe ApplicationFrameHost.exe")
Run 'Calc'
  }
Other apps seem to work as expected but not the calculator, for example:

Code: Select all

#F2:: {
 If WinExist('ahk_exe outlook.exe')
  WinActivate
 Else Run 'outlook'
}

Alt & F3:: {
 If WinExist('ahk_exe notepad.exe')
  WinActivate
 Else Run 'notepad'
}
Thanks again for your help and suggestions.

NalaEdaw
Posts: 27
Joined: 15 Mar 2023, 14:30

Re: Opening Just One Instance Of Calculator

Post by NalaEdaw » 17 Jan 2024, 15:50

Ok got it, many thanks to all who helped, @MysticDude code worked after I changed Calculator to Kalkylatorn which is Swedish for calculator. I didnt guess that at first as calc.exe opens the calculator.

Code: Select all

F4:: {
If WinExist('Kalkylatorn ahk_class ApplicationFrameWindow ahk_exe ApplicationFrameHost.exe')
  WinActivate
Else Run 'calc'
  }

Post Reply

Return to “Ask for Help (v2)”