Auto Maximize skype live conversation window with Autohotkey - 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.

Related

Issues sending key events to browser window autohotkey

I am trying to open up a webpage and save it as a complete file. This should be a relatively easy task for autohotkey. For some reason my script is not sending key events to the window. Here's the script:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn All, StdOut ; 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.
Run, www.google.com
WinWaitActive firefox.exe
sleep, 4000
ControlSend, ahk_class MozillaWindowClass, ^s
What would be a better approach to this problem?
Here is my solution:
Run, www.google.com
WinWaitActive ahk_exe firefox.exe
sleep, 4000
Send ^s
There were two main things that were changed for this to work
Include ahk_exe before the name of the exe in the WinWaitActive conditional
Removed the ControlSend and replaced it with a regular Send, since we are already waiting for the Window to be activated
Hope this helps, feel free to ask for any more clarification or help if you need it
ControlSend, ahk_parent, ^s, ahk_class MozillaWindowClass

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

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

AutoHotKey IfWinActive not working

I'm trying to use a simple script that would work only when the active window is open and when you're in that window (e.g. some windowed mode game). So the script works, but it also works outside the active window, e.g. on desktop or a browser too. I don't need that. I need it to work only in the active window I set.
The script:
RButton::rightMouseClick()
rightMouseClick(){
if WinActive("ahk_class Notepad") {
WinMaximize
Send, Some text.{Enter}
return
}
}
So, this example works when you go to Notepad and right click. But also now right click doesn't work anywhere else on the computer? It works only if you hold down shift?!
How do I make this script react/work/run only when active window is Notepad? And not work globally.
Here is my suggestion:
#If WinActive("ahk_class Notepad") ;if the window with the ahk_class "Notepad" is active
RButton:: ;this hotkey is only enabled while the above statement is true
WinMaximize ;maximize the active window
Send, Some text.{Enter} ;send some keyboard input
Return ;end of the hotkey
#If ;end of the special "#If" statement
Correct indentation alone can help a lot understanding the code.
#IfWinActive ahk_class Notepad
RButton::
WinMaximize
Send, Some text.{Enter}
Return
#If

How to continuously run an autohotkey script?

I am trying to make a basic shortcut for windowsHome + Shift + w. If word is open, I would like to set Word as the active window and maximize Word; else, if word isn't open, I would like to open a specified word document. This script works fine running once but can't run multiple times without restarting the script. I tried adding #Persistent and a never-ending while loop but this still doesn't work. What I am doing wrong? Thank you for your help in advance! I will definitely rate you up if you help me out.
#Persistent
#NoEnv
#Warn
SendMode Input
SetWorkingDir %A_ScriptDir%
#+w::
while 1
{
IfWinExist *.docx - Microsoft Word
{
WinActivate
WinMaximize
}
else
{
Run, C:\Users\myHome\Desktop\311.docx
}
}
return
This is working for me:
SendMode Input
SetWorkingDir %A_ScriptDir%
#+w::
IfWinExist ahk_class OpusApp
{
WinActivate ahk_class OpusApp
WinMaximize ahk_class OpusApp
}
else
{
Run, C:\Users\myHome\Desktop\311.docx
WinWait ahk_class OpusApp
WinActivate ahk_class OpusApp
}
return
I highly recommend using the ahk_class for this purpose.
Also, you don't need the loop, otherwise it will consistently loop after the keys are pressed, keeping the window maximized. In this example, the actions happen after the keys are pressed, but only happen once.
Also, the ahk_class OpusApp is the correct class for Microsoft Word 2010.
Let me know if you need any more help.

Mouse Control with autohotkey

I'm making a script for 2 differents windows, and when I click on the first window, a click in the same position in the other window occurs.
The problem is, my script make the click but the x axis on the second window is always 0... and I don't know why
Maybe you got a solution or another way to script it?
This is my script:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Recommended for catching common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;retrouver les id de 2 fenetres
WinGet, first_id, ID, window1
WinGet, sec_id, ID, window2
;activation des fenetres
WinActivate, ahk_id %sec_id%
WinActivate, ahk_id %first_id%
; fonction pour quitter la macro
~Esc::ExitApp
return
;test repeter clic souris
;LeftClic
~LButton::
{
MouseGetPos, xposi, yposi
ControlClick, x%xposi% y%yposi%, ahk_id %first_id%,,LEFT
WinActivate, ahk_id %sec_id%
ControlClick, x%xposi% y%yposi%, ahk_id %sec_id%,,LEFT
WinActivate, ahk_id %first_id%
MouseMove, xposi, yposi
}
return
First and foremost, to quote the documentation for MouseGetPos:
The retrieved coordinates are relative to the active window unless
CoordMode was used to change to screen coordinates.
That means it's relative to the first window.
If these windows are not identical (in any case) the chances of this working for you are slim.
With that said, if they are identical you could change CoordMode to Screen and use WinMove to size and position the second window exactly as the first, after you activate it, and then just use the Click command.
The only other thing I can think of is looking at ControlClick's options, and you will see there is Xn and Yn, which is relative to a control. Every control is in fact a window, and sometimes an application only has one control, the main window.
Side-note: You wouldn't need curly brackets {} in your script.
They are only needed in a hotkey when you have a loop or a multi-line if / else block.