Needing differentiate "same class - different app" Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Guill
Posts: 139
Joined: 09 Jun 2016, 22:00

Needing differentiate "same class - different app"

06 May 2018, 22:50

Hi guys,

I have the following need:

I am using LibreOffice, and I need to differentiate its function "Writer" (equivalent to Word) of "Impress" (PowerPoint)

I need the following script to work:

Code: Select all

F11 ::
IfWinExist, ahk_class SALFRAME ("Writer")
WinActivate
Return

F12 ::
IfWinExist, ahk_class SALFRAME ("Impress")
WinActivate
Return
The drawback is that the program has a unique "class" (called SALFRAME) for all its applications.
And while both programs have their own "exe", I tried the following and it does not work.

Code: Select all

F11 ::
IfWinExist ahk_exe swriter.exe
Winactivate

F12 ::
IfWinExist ahk_exe simpress.exe
Winactivate


How could I make this work?
icuurd12b42
Posts: 202
Joined: 14 Aug 2016, 04:08

Re: Needing differentiate "same class - different app"

07 May 2018, 00:13

try the WinExist function instead maybe?
poetbox
Posts: 112
Joined: 18 Apr 2018, 20:47

Re: Needing differentiate "same class - different app"

07 May 2018, 04:27

Any other information about them?or privide a screenSnap here?
User avatar
BriHecato
Posts: 124
Joined: 18 Jul 2017, 07:17

Re: Needing differentiate "same class - different app"

07 May 2018, 04:29

Exe is also the same - soffice.bin - so it wont work
Use proper wintitle - https://autohotkey.com/docs/misc/WinTitle.htm (Writer, Impress, Calc in the actual title bar of windowed application), and SetTitleMatch ,2
poetbox
Posts: 112
Joined: 18 Apr 2018, 20:47

Re: Needing differentiate "same class - different app"

07 May 2018, 04:33

Guill wrote:Hi guys,

I have the following need:

I am using LibreOffice, and I need to differentiate its function "Writer" (equivalent to Word) of "Impress" (PowerPoint)

I need the following script to work:

Code: Select all

F11 ::
IfWinExist, ahk_class SALFRAME ("Writer")
WinActivate
Return

F12 ::
IfWinExist, ahk_class SALFRAME ("Impress")
WinActivate
Return
The drawback is that the program has a unique "class" (called SALFRAME) for all its applications.
And while both programs have their own "exe", I tried the following and it does not work.

Code: Select all

F11 ::
IfWinExist ahk_exe swriter.exe
Winactivate

F12 ::
IfWinExist ahk_exe simpress.exe
Winactivate


How could I make this work?
You can use ifwinexist by the title of the window!
Remember to add this line at the first:SetTitleMatchMode, 2
Guill
Posts: 139
Joined: 09 Jun 2016, 22:00

Re: Needing differentiate "same class - different app"  Topic is solved

07 May 2018, 06:09

Thanks to all!

The solution is:

Code: Select all

F11 ::
SetTitleMatchMode 2
IfWinExist, Writer
WinActivate


F12 ::
SetTitleMatchMode 2
IfWinExist, Impress
WinActivate

poetbox
Posts: 112
Joined: 18 Apr 2018, 20:47

Re: Needing differentiate "same class - different app"

07 May 2018, 22:23

OK,that's right.
authough "SetTitleMatchMode 2" can write alone at the 1st line for F11&F11.

SetTitleMatchMode 2
F11 ::
IfWinExist, Writer
WinActivate


F12 ::
IfWinExist, Impress
WinActivate
User avatar
BriHecato
Posts: 124
Joined: 18 Jul 2017, 07:17

Re: Needing differentiate "same class - different app"

19 May 2018, 15:48

Guill wrote:Thanks to all!
The solution is:

Code: Select all

F11 ::
SetTitleMatchMode 2
IfWinExist, Writer
WinActivate

F12 ::
SetTitleMatchMode 2
IfWinExist, Impress
WinActivate

And what about if you have "Writer.txt" file opened in Notepad ?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Needing differentiate "same class - different app"

19 May 2018, 16:09

in ahk_class SALFRAME ("Writer") is SALFRAME the class name or SALFRAME ("Writer")

u could combine them:

Code: Select all

F11::
if (WinExist("ahk_class SALFRAME ahk_exe swriter.exe"))
	WinActivate
Return

F12::
if (WinExist("ahk_class SALFRAME ahk_exe simpress.exe"))
	WinActivate
Return
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Needing differentiate "same class - different app"

19 May 2018, 17:58

- I tried opening LibreOffice Writer and LibreOffice Impress, the processes both had the same PID/process path/process name (soffice.bin)/class (SALFRAME)/command line.
- They also both had the same window style/ex. style: 0x15CF0000 / 0x00000100.
- I tried to retrieve a list of control ClassNNs, both windows appeared to have no controls.
- Thus using the window title seems like the best approach.
- Possibly there are some other distinguishing features that I haven't thought of. Using Acc (MSAA) might be a possibility but seems overkill. Cheers.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, Google [Bot], Peiya, ShatterCoder, uchihito, zvit and 322 guests