How to find OneNote windows 10 in AutoHotKey's if winexist? - autohotkey

I'm trying to build a script that allows me to open and use OneNote (The store app not OneNote 2016) with a hotkey, but I would like to use the same hotkey to switch the the app from another window. I have accomplished this with many other programs, but never with windows store app. Here is the code I'm trying to use.
#If WinExist("OneNote ahk_class ApplicationFrameWindow", "OneNote")
{
WinActivate,
}
Else
Run, C:\Users\ChrisCochrun\Documents\OneNote
#If
Unfortunately it's not detecting that the window exists and it'll only just launch a new instance of onenote. I've looked for answers, but I'm having trouble making it so that AHK actually sees the window already running and jumping to it.
Thanks very much for any help at all!

If the window's title doesn't start with "OneNote", you need to use
SetTitleMatchMode 2.
The #If-directive is only used for creating context-sensitive hotkeys and hotstrings.
F1:: ; or a hotkey of your choise
SetTitleMatchMode 2
If WinExist("OneNote ahk_class ApplicationFrameWindow", "OneNote")
WinActivate
Else
Run, C:\Users\ChrisCochrun\Documents\OneNote
return

rshfit::
SetTitleMatchMode 2
If WinExist("OneNote for Windows 10")
WinActivate return
;If I use rshift to activate Onenote for Windows 10

Related

Autohotkey script to perform action when Microsoft Edge is active

I'm trying to write an script in order to perform actions when Microsoft Edge windows being active. I tried these scripts:
#IfWinActive Microsoft edge
~$l::
KeyWait,l,T0.25
if (ErrorLevel)
{
send,^l
sleep,100
send,{Delete}
}
return
But it doesn't recognize the windows. I tried different names such #IfWinActive, ahk_class Microsoft Edge and #IfWinActive Microsoft Edge.exe too. but neither of them worked.
Using Window Spy on a new Edge tab shows me this:
Of the three main options that you would use for an #IfWinActive statement (WinTitle, ahk_class, or ahk_exe), the ahk_exe would likely be the best option for creating a script that will always work in MS Edge, and only in MS Edge based on what the Windows Spy displays.
Based on this, I created this generic script to check if a hotkey was triggered in Edge
#IfWinActive, ahk_exe msedge.exe
^q::MsgBox Hotkey Triggered in Edge (msedge.exe)
#If
^q::MsgBox Hotkey Triggered in a different program
Incorporating your original script into this gives:
#IfWinActive, ahk_exe msedge.exe
~$l::
KeyWait,l,T0.25
if (ErrorLevel)
{
send,^l
sleep,100
send,{Delete}
}
return
For more info about #IfWinActive, see the docs.
Also relevant: Post on AHK forums on how to use the #IfWinActive with program names, ahk_exe, and ahk_class.

How to start a program if not already started, put on focus if already started?

I would like to make a ahk script to start apps if they are not currently started and maximize them if they are. Is it possible using AHK ?
CapsLock & w::
Run firefox.exe
Return
Something like this but make it so that if I press CapsLock & w and then minimize firefox, pressing CapsLock & w would bring it back maximized / in focus. Any ideas? Thanks!
Sure, this is very easy and doable with AHK.
Here's a very easy and straight forward example
CapsLock & w::
if (WinExist("ahk_exe notepad.exe"))
{
WinActivate, ahk_exe notepad.exe
WinMaximize, ahk_exe notepad.exe
}
else
Run, notepad.exe
return
ahk_exe (docs) is used to refer to windows by their process. It's very convenient.
The code that you are looking for is somewhat similar to the example they give in the docs for WinActivate
So modifying that example for your purpose, and adding conditionals would give you:
CapsLock & w::
if WinExist("ahk_exe firefox.exe")
if WinActive("ahk_exe firefox.exe")
WinMinimize
else
WinActivate
else
Run firefox.exe
Return
Take note that this script will currently only minimize a Firefox window if it is the currently active window. If you need it to minimize a Firefox in the background, the script would potentially be a bit more complex since you could possibly have multiple Firefox windows open, and you would need to provide conditions and logic to handle cases like those. However, if you need this functionality, describe what behavior you would like to occur if this condition occurs, and I can work on it.

Auto Maximize skype live conversation window with Autohotkey

Here is what I'm trying to do and would greatly appreciate any help here.
I am trying to automate maximizing the live conversation window in skype with an Autohotkey script. I'm trying to make it so I can call into a remote machine using skype and have it auto answer (this is native in skype)...once I have a live conversation window I would like to maximize the live conversation window to fill the screen.
I've given this a shot but somehow don't think that I have the correct ahk_class for the live conversation window but there may be something else I am missing. I've placed a the code I've tried using below...any help would be great.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#Persistent
IfWinExist, TLiveConversationWindow ;
{
WinActivate
WinMaximize
send !{Enter};When using skype normally this Alt+Enter will maximize the window
return
}
I also tried to use this code to determine the proper class for the live conversation window...but has not helped as of yet.
Alt & Enter::
IfWinExist, TLiveConversationWindow
WinActivate
ControlFocus, ClassNN TLiveConversation1
ControlClick, ClassNN TLiveConversation1, , , , 2,
MouseClick, left, , , 2
send !{Enter}
; now we get the ID & CLASS
WinGet, Active_Window_ID, ID, A
WinGetClass, Active_Window_Class, A
MsgBox, The active window's class is "%Active_Window_class%" and ID is %Active_Window_ID%
Was able to get a simplified version of the code to work with a hotkey to initiate but have not been able to get the WinWait function to work as per #Schneyer.
Functioning Code activated by hotkey
#NoEnv
#Warn
#Persistent
SendMode Input
SetWorkingDir %A_ScriptDir%
; Skype Maximizer initiating functions
^!p::
;WinWait ahk_class TLiveConversation1
;WinWait ahk_class TConversationForm
;WinWait ahk_class TLiveConversationWindow
;WinMaximize ahk_class TLiveConversation1
;functioning code
;Activate tSkMainForm.
WinActivate ahk_class tSkMainForm
;Send Alt Enter Input to maximize.
SendInput !{Enter}
;TLiveConversationWindow Always On Top
WinSet, AlwaysOnTop,,ahk_class TLiveConversationWindow
;Minimize main form
WinMinimize ahk_class tSkMainForm
Return
When swapping the ^!p:: with any of the WinWait Functions nothing seems to happen. The WinWait seems like it should be the proper method, any thoughts on why it won't work?
Problems
#persistent lets the script run, but your code still gets executed only once when you start the script. After that it stays active but does nothing.
Use a WinWait to wait for the window to appear (wrap it in a Loop if you want it to run more than once).
Use ahk_class to to search for a window class instead of the window title
Working code
You can use the Window Spy tool which is included in AHK. Use the tray icon menu of a running AHK script to start it.
I use TConversationForm in the code, but it works with every window class.
#NoEnv
#Warn
SendMode Input
SetWorkingDir %A_ScriptDir%
WinWait ahk_class TConversationForm
WinActivate
WinMaximize
Scanning through AHK forums I was able to find a post that led me to the answer for this little problem. Check the below link for further information.
https://autohotkey.com/board/topic/96491-detect-when-a-classnn-window-exists/
The problem with using ahk_class to identify when a skype call was active is that the "active call window" identified as classNN TLiveConversation1 in the inspector was actually a Control within the window of ahk_class tSkMainForm rather than a Window. This made the WinWait function ineffective at identifying it when the call initiated.
In order to identify the Control it is necessary to loop through the controls (using WinGet) in ahk_class tSkMainForm until the TLiveConversation exists and then kick off any subroutines needed. For me that was to maximize the live conversation window.
You'll see the code to do this starting with the WinGet function. All of this is wrapped in a while loop so that it will run persistently allowing it to be called over and over. In essence this code will do the following:
Create a list (SkypeControlList) of controls existing in ahk_class tSkMainForm.
Continually Loop Through SkypeControlList
When a new Live Conversation is initiated a control TLiveConversation1 will exist
Once TLiveConversation1 esists run necessary code
#NoEnv
#Warn
#Persistent
SendMode Event
SetWorkingDir %A_ScriptDir%
DetectHiddenWindows, on
stop = 0
Loop
{
While stop = 0
{
WinGet, SkypeControlList, ControlList, ahk_class tSkMainForm
Loop, Parse,SkypeControlList, `n
{
;Loop to search for control TLiveConversation1
if (A_LoopField = "TLiveConversation1")
{
;Deactivate active screensaver
PostMessage, 0x0112, 0x0F060, 0,, A
;RegWrite REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, ScreenSaveActive, 0
;SetKeyDelay, 500
Send {Esc}
;Activate tSkMainForm.
WinActivate ahk_class tSkMainForm
;Send Alt Enter Input to maximize.
Send !{Enter}
;TLiveConversationWindow Always On Top
WinSet, AlwaysOnTop,,ahk_class TLiveConversationWindow
stop = 1
sleep, 100
}
}
}
IfWinExist ahk_class TLiveConversationWindow
{
stop = 1
sleep, 1000
}
IfWinNotExist ahk_class TLiveConversationWindow
{
;Minimize all windows by win+D show desktop
send #d
sleep,1000
; is that call quality feedback window up? kill it.
SetTitleMatchMode, Regex
WinClose, ^Skype.*Call quality feedback$
stop = 0
}
sleep 1000
}
Return
The above code works great as long as there is no screen saver active on the machine being called. If there is an active screen saver the call will answer but the screen saver will not go away. You can see remnants of code trying to wake the computer from a screen saver (This does not currently work).
I've also added a few bits of code to clean up the experience such as removing the call quality popup window that skype throws up after a call as well as clearing the desktop after the call ends.
Thanks to #Blauhirn and #Schneyer for their input in trying to get this solved.

Autohotkey autocomplete limit to certain windows

I am trying to use the Autohotkey autocomplete script here: http://www.autohotkey.com/board/topic/60998-autocomplete-updated-26713/ but limit it to certain windows. Enclosing the entire script within #IfWinActive does not seem to work. I really like this completion script but would not want it showing up all over the place. Is there a way to limit the autocompletion to specific windows?
A quick study of the source code showed that every keypress results in a call of the Suggest subroutine. This seems to be a good place to check for the active window. I've implemented a minimal change in the source, you can check it out here.
First, you have to define which windows you want to exlude from the functionality, I achieved this by defining a window group:
GroupAdd, excludedWins, ahk_class CabinetWClass ; windows explorer
GroupAdd, excludedWins, ahk_class DV2ControlHost ; start menu search bar
GroupAdd, excludedWins, ahk_class ConsoleWindowClass ; console
Please note that I'm using Windows 7; maybe, the windows have other identifiers in other versions.
Second, you need to tell the Suggest subroutine to ignore these windows:
Suggest:
IfWinActive, ahk_group excludedWins
{
return
}
It seems to work, but I only tested very superficially and didn't investigate the source code dependencies. Let me know how it works for you.

script opens document but not with hotkey

I'm creating a script to open and run with a program that has no help files but comes with a huge PDF manual. There is no way to open it from the program, so I have set up a command to open it. The command opens the PDF when run on its own, but when I assign a hotkey, it does not work. What very basic information am I missing?
thanks,
Ellen
SetTitleMatchMode, 2
runwait C:\Program Files\FontLab\TypeTool3\TTool3.exe, , max
IfWinExist TypeTool 3
Return
ExitApp
Return
#ifWinActive, TypeTool 3
$wheeldown::wheelup
$wheelup::wheeldown
F1::
Run, C:\Documents and Settings\Ellen\My Documents\TypeTool3WinMan.pdf
Return
#ifWinActive
Do you have a Return before your #IfWinActive statement? If not then during startup the script will run every line until it hits the first Return, which seems to be all the way to the end for you. So also place a return after your Run, C:..... command
And oh.. Are you sure about that weird long ahk_class? It could be correct but it looks strange and if this is just a littlebit off, your hotkey would never work, so try it first with the #IfWinActive line commented out.
SetTitleMatchMode, 2
;All the stuff you want to run at startup....
Return
#ifWinActive, (part of) the window name here e.g. Excel
$wheeldown::wheelup
$wheelup::wheeldown
F1::
Run, C:\Documents and Settings\Ellen\My Documents\TypeTool3WinMan.pdf
Return
#ifWinActive