Windows 10 apps
Windows 10 apps
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.
Re: Windows 10 apps
To clearly identify such a window, combine
- SetTitleMatchMode 2
- multiple criteria within the WinTitle parameter
- WinText
Code: Select all
SetTitleMatchMode 2
; If WinActive("WinTitle ahk_class WinClass", "WinText", "ExcludeTitle", "ExcludeText")
If WinActive("Photos ahk_class ApplicationFrameWindow", "Photos")
Re: Windows 10 apps
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.
-
- Posts: 1472
- Joined: 05 May 2018, 12:23
Re: Windows 10 apps
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
Re: Windows 10 apps
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.
AHKStudent what should I exclude? I don't get that part.
Re: Windows 10 apps
Hello SomeNewb,SomeNewb wrote: ↑20 Feb 2019, 23:21Yes 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.
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
Re: Windows 10 apps
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 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):
or, as you said in your OP, here is without ahk_class or ahk_exe (but much less reliable):
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
Code: Select all
SetTitleMatchMode, 2
#IfWinActive Photos
q::
MsgBox Works only in Photos App!
return
#IfWinNotActive Photos
q::
MsgBox In another app
return
-TL
Re: Windows 10 apps
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.
Re: Windows 10 apps
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
Re: Windows 10 apps
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()
Re: Windows 10 apps
Okay so I see a couple of issues here. I think your main issue though is that usingSomeNewb wrote: ↑21 Feb 2019, 01:12Code: 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()
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
So you script right there currently reads something like:WinActive() / IfWin[Not]Active
Checks if the specified window exists and is currently active (foremost). If it is, WinActive() returns its Unique ID (HWND).
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
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
-TL
Re: Windows 10 apps
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:
But now I get one less headbang at least.
After recently forcefully moving to windows 10 from Win7 this has been my life:
But now I get one less headbang at least.
Re: Windows 10 apps
Lexikos wrote a solution to retrieve Application Names from UWA apps a while back... https://www.autohotkey.com/boards/viewtopic.php?t=13818#p73137
Re: Windows 10 apps
I don't know how to implement that 0x00.
Re: Windows 10 apps
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
}
Re: Windows 10 apps
Thanks a lot.
Re: Windows 10 apps
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.
Who is online
Users browsing this forum: No registered users and 147 guests