Windows 10 apps

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
SomeNewb
Posts: 52
Joined: 08 Jan 2017, 18:43

Windows 10 apps

19 Feb 2019, 18:49

Windows 10 apps such as Photos have the same class and exe names as windows settings. So is there any way to make a script for say just the Photos app without using ahk_class or ahk_exe? I already tried titlematchmode with the name "photos" but that doesn't work.
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: Windows 10 apps

20 Feb 2019, 01:16

To clearly identify such a window, combine
  • SetTitleMatchMode 2
  • multiple criteria within the WinTitle parameter
  • WinText
e.g.:

Code: Select all

SetTitleMatchMode 2
; If WinActive("WinTitle ahk_class WinClass", "WinText", "ExcludeTitle", "ExcludeText")
If WinActive("Photos ahk_class ApplicationFrameWindow", "Photos")
SomeNewb
Posts: 52
Joined: 08 Jan 2017, 18:43

Re: Windows 10 apps

20 Feb 2019, 16:32

Well it works but the thing is I want to set my mouse xbuttons to go forward/back through pictures in Photos. But setting this code I get a "duplicate hotkey" error because I got the same buttons remapped to other programs as well.
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Windows 10 apps

20 Feb 2019, 16:49

SomeNewb wrote:
20 Feb 2019, 16:32
Well it works but the thing is I want to set my mouse xbuttons to go forward/back through pictures in Photos. But setting this code I get a "duplicate hotkey" error because I got the same buttons remapped to other programs as well.
Try using the exclude
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: Windows 10 apps

20 Feb 2019, 22:25

SomeNewb wrote:
20 Feb 2019, 16:32
Well it works but the thing is I want to set my mouse xbuttons to go forward/back through pictures in Photos. But setting this code I get a "duplicate hotkey" error because I got the same buttons remapped to other programs as well.
Hi SomeNewb, look into this: Variant (Duplicate) Hotkeys
A particular hotkey or hotstring can be defined more than once in the script if each definition has different #IfWin criteria. These are known as hotkey variants. For example:

#IfWinActive ahk_class Notepad
^!c::MsgBox You pressed Control+Alt+C in Notepad.
#IfWinActive ahk_class WordPadClass
^!c::MsgBox You pressed Control+Alt+C in WordPad.
#IfWinActive
^!c::MsgBox You pressed Control+Alt+C in a window other than Notepad/WordPad.
S↓
If more than one variant is eligible to fire, only the one closest to the top of the script will fire. The exception to this is the global variant (the one with no #IfWin criteria): It always has the lowest precedence; therefore, it will fire only if no other variant is eligible (this exception does not apply to hotstrings).
-TL
SomeNewb
Posts: 52
Joined: 08 Jan 2017, 18:43

Re: Windows 10 apps

20 Feb 2019, 23:21

Yes Tigerlily I got a whole bunch of #IfwinActive codes in the same ahk file. This particular code's if winactive doesn't function as #ifwinactive, as in it doesn't recognize Photos as an app so I get the duplicate hotkey error.

AHKStudent what should I exclude? I don't get that part.
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: Windows 10 apps

21 Feb 2019, 00:11

SomeNewb wrote:
20 Feb 2019, 23:21
Yes Tigerlily I got a whole bunch of #IfwinActive codes in the same ahk file. This particular code's if winactive doesn't function as #ifwinactive, as in it doesn't recognize Photos as an app so I get the duplicate hotkey error.

AHKStudent what should I exclude? I don't get that part.
Hello SomeNewb,

This works for me, let me know if it works for you:

Code: Select all

#IfWinActive Photos, Photos
q::
MsgBox Works only in Photos App!
return

#IfWinNotActive Photos, Photos
q::
MsgBox In another app
return
-TL
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: Windows 10 apps

21 Feb 2019, 00:15

This also works and may be a bit more reliable since the WinText could change in some parts of the Photos app. You can also use ahk_exe ApplicationFrameHost.exe instead of ahk_class ApplicationFrameWindow. I beleive your syntax may have not been correct for use of #IfWinActive - I made the same mistake not so long ago :P If you post the code you are using, we may be able to help you better though.

Make sure you have SetTitleMatchMode, 2 above the code (as shown below):

Code: Select all

SetTitleMatchMode, 2


#IfWinActive Photos ahk_class ApplicationFrameWindow
q::
MsgBox Works only in Photos App!
return

#IfWinNotActive Photos ahk_class ApplicationFrameWindow
q::
MsgBox In another app
return
or, as you said in your OP, here is without ahk_class or ahk_exe (but much less reliable):

Code: Select all

SetTitleMatchMode, 2


#IfWinActive Photos
q::
MsgBox Works only in Photos App!
return

#IfWinNotActive Photos
q::
MsgBox In another app
return
-TL
SomeNewb
Posts: 52
Joined: 08 Jan 2017, 18:43

Re: Windows 10 apps

21 Feb 2019, 00:46

This only works one time, as my own code did before I asked for help. It works one time as in only one physical button press, after that the code doesn't know we're in Photos anymore and reverts back to whatever the button was set to do if it wasn't in Photos.
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: Windows 10 apps

21 Feb 2019, 00:55

SomeNewb wrote:
21 Feb 2019, 00:46
This only works one time, as my own code did before I asked for help. It works one time as in only one physical button press, after that the code doesn't know we're in Photos anymore and reverts back to whatever the button was set to do if it wasn't in Photos.
That's really odd, as that's not the case for me. I can press "q" as many times as I want and in as many different windows as I want, and unless I am in the Photos app, I will keep getting the MsgBox that reads "In another app". I do not need to re-run the script. I thoroughly tested this, as I will need to use this same sort of thing in a program I am currently building out. I think there is something else in your code that is preventing this from happening, I am guessing it is the order of your code. Please post your code if you want more help.. you haven't posted any of your own code.
-TL
SomeNewb
Posts: 52
Joined: 08 Jan 2017, 18:43

Re: Windows 10 apps

21 Feb 2019, 01:12

Code: Select all

#InstallKeybdHook
#InstallMouseHook
#SingleInstance force
#NoEnv
#NoTrayIcon
#Warn
SendMode Input
SetWorkingDir %A_ScriptDir%
CoordMode, Mouse, Screen

;------------------------------------------------------------------------------------------Zoner Photo Studio
#IfWinActive ahk_exe Zps.exe
vk05::SendInput {xbutton2} ; XButton1 === Send Xbutton2: Next Photo.
vk06::SendInput {xbutton1} ; XButton2 === Send Xbutton1: Previous Photo.
return

;------------------------------------------------------------------------------------------Photos
SetTitleMatchMode 2
; If WinActive("WinTitle ahk_class WinClass", "WinText", "ExcludeTitle", "ExcludeText")
#If WinActive("Photos ahk_class ApplicationFrameWindow", "Photos")
vk05::SendInput {Right} ; XButton1 === Send Right: Next Photo.
return

#IfWinActive Photos
vk06::SendInput {Left} ; XButton2 === Send Left: Previous Photo.
return


;------------------------------------------------------------------------------------------Adobe Photoshop
#IfWinActive ahk_class Photoshop
vk05::SendInput ^{vkBB} ; XButton1 === Send Ctrl + +: Zoom in.
vk06::SendInput ^{vkBD} ; XButton2 === Send Ctrl + -: Zoom out.
vk04::SendInput {vk4D} ; Middle button === Send M: Rectangular Marquee Tool.
vk87::sendinput, ^{vk59} ; F24 (set in mouse middle left button) === Send Ctrl+Y: Redo.
vk86::Sendinput, ^{vk5A} ; F23 (set in mouse middle right button) === Send Ctrl+Z: Undo.
!vk9F::SendInput ^{vk59} ; Alt + Wheel up === Send Ctrl+Y: Redo.
!vk9E::SendInput ^{vk5A} ; Alt + Wheel down === Send Ctrl+Z: Undo.
^vk53::SendInput ^{vk4C} ; Ctrl+S (set in mouse right side lower button) === Send Ctrl+L: Levels.
Return()
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: Windows 10 apps

21 Feb 2019, 08:58

SomeNewb wrote:
21 Feb 2019, 01:12

Code: Select all

#InstallKeybdHook
#InstallMouseHook
#SingleInstance force
#NoEnv
#NoTrayIcon
#Warn
SendMode Input
SetWorkingDir %A_ScriptDir%
CoordMode, Mouse, Screen


;------------------------------------------------------------------------------------------Zoner Photo Studio
#IfWinActive ahk_exe Zps.exe
vk05::SendInput {xbutton2} ; XButton1 === Send Xbutton2: Next Photo.
vk06::SendInput {xbutton1} ; XButton2 === Send Xbutton1: Previous Photo.
return

;------------------------------------------------------------------------------------------Photos
SetTitleMatchMode 2
; If WinActive("WinTitle ahk_class WinClass", "WinText", "ExcludeTitle", "ExcludeText")
#If WinActive("Photos ahk_class ApplicationFrameWindow", "Photos")
vk05::SendInput {Right} ; XButton1 === Send Right: Next Photo.
return

#IfWinActive Photos
vk06::SendInput {Left} ; XButton2 === Send Left: Previous Photo.
return


;------------------------------------------------------------------------------------------Adobe Photoshop
#IfWinActive ahk_class Photoshop
vk05::SendInput ^{vkBB} ; XButton1 === Send Ctrl + +: Zoom in.
vk06::SendInput ^{vkBD} ; XButton2 === Send Ctrl + -: Zoom out.
vk04::SendInput {vk4D} ; Middle button === Send M: Rectangular Marquee Tool.
vk87::sendinput, ^{vk59} ; F24 (set in mouse middle left button) === Send Ctrl+Y: Redo.
vk86::Sendinput, ^{vk5A} ; F23 (set in mouse middle right button) === Send Ctrl+Z: Undo.
!vk9F::SendInput ^{vk59} ; Alt + Wheel up === Send Ctrl+Y: Redo.
!vk9E::SendInput ^{vk5A} ; Alt + Wheel down === Send Ctrl+Z: Undo.
^vk53::SendInput ^{vk4C} ; Ctrl+S (set in mouse right side lower button) === Send Ctrl+L: Levels.
Return()
Okay so I see a couple of issues here. I think your main issue though is that using

Code: Select all

SetTitleMatchMode, 2
:
MatchMode
One of the following digits or the word RegEx:

1: A window's title must start with the specified WinTitle to be a match.
2: A window's title can contain WinTitle anywhere inside it to be a match.
3: A window's title must exactly match WinTitle to be a match.


This means that any window title that contains the string "Photos" will match, which Photos and Photoshop both contain. This is another reason why you will need to use #IfWinActive Photos ahk_class ApplicationFrameWindow or ahk_exe ApplicationFrameHost.exe

Also, you need to put SetTitleMatchMode 2 at the top of your script, not sure why exactly, but it seems to mess with the script functioning correctly when not in the Auto-Execute section with a hotkey script like this. If you think about it, your script the way it's set up would never reach that line of code to execute on because there are returns before it and hotkeys after it, but no hotkey or subroutine to activate it.

You don't need to put SendInput, when you've set SendMode to Input, just simply Send will work.

The return can drop the () at the end of your script, it is pointless, although still should work fine.

#If WinActive("Photos ahk_class ApplicationFrameWindow", "Photos") this does not work because using the WinActive Function like that will return a value that you must do something with
WinActive() / IfWin[Not]Active
Checks if the specified window exists and is currently active (foremost). If it is, WinActive() returns its Unique ID (HWND).
So you script right there currently reads something like:

If "930452"
Then use these hotkeys

You will need to set the hWnd to a variable and the check if it does not equal 0, like:

Code: Select all

Photos_hWnd := WinActive("Photos ahk_exe ApplicationFrameHost.exe")
#If (Photos_hWnd != 0) {
vk05::Send {Right} ; XButton1 === Send Right: Next Photo.
vk06::SendInput {Left} ; XButton2 === Send Left: Previous Photo.
}
return
or possibly:

Code: Select all

#If (WinActive("Photos ahk_exe ApplicationFrameHost.exe") != 0) {
vk05::Send {Right} ; XButton1 === Send Right: Next Photo.
vk06::SendInput {Left} ; XButton2 === Send Left: Previous Photo.
}
return
Let me know if that helps.
-TL
SomeNewb
Posts: 52
Joined: 08 Jan 2017, 18:43

Re: Windows 10 apps

23 Feb 2019, 21:04

Thanks a lot for your help with the script. It worked like a charm. :)

After recently forcefully moving to windows 10 from Win7 this has been my life: :headwall:
But now I get one less headbang at least.
0x00
Posts: 89
Joined: 22 Jan 2019, 13:12

Re: Windows 10 apps

24 Feb 2019, 07:25

Lexikos wrote a solution to retrieve Application Names from UWA apps a while back... https://www.autohotkey.com/boards/viewtopic.php?t=13818#p73137
SomeNewb
Posts: 52
Joined: 08 Jan 2017, 18:43

Re: Windows 10 apps

25 Feb 2019, 03:37

I don't know how to implement that 0x00.
0x00
Posts: 89
Joined: 22 Jan 2019, 13:12

Re: Windows 10 apps

25 Feb 2019, 03:46

EDIT: Corrected To 'Microsoft.Photos.exe'

Code: Select all

q::MsgBox %  WinGetActiveProcessName()	;get what the Photo's Detected  Name Is & Use that below... 

#If WinGetActiveProcessName() = "Microsoft.Photos.exe"
vk05::Send {Right} ; XButton1 === Send Right: Next Photo.
vk06::SendInput {Left} ; XButton2 === Send Left: Previous Photo.
#If

WinGetActiveProcessName() {	;Lexikos
    WinGet name, ProcessName, A
    if (name = "ApplicationFrameHost.exe") {
        ControlGet hwnd, Hwnd,, Windows.UI.Core.CoreWindow1, A
        if hwnd {
            WinGet name, ProcessName, ahk_id %hwnd%
        }
    }
    return name
}
SomeNewb
Posts: 52
Joined: 08 Jan 2017, 18:43

Re: Windows 10 apps

25 Feb 2019, 08:04

Thanks a lot.
SomeNewb
Posts: 52
Joined: 08 Jan 2017, 18:43

Re: Windows 10 apps

28 Feb 2019, 05:44

If anyone else wants to use this: The code by Tigerlily also works when Photos is fullscreen or during slideshow. The one by Lexikos doesn't.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 147 guests