Skip to content

Commit

Permalink
Merge pull request #4 from WoosterFromWA/fix_slow_switching
Browse files Browse the repository at this point in the history
simplified internals, faster
  • Loading branch information
WoosterInitiative authored Dec 14, 2018
2 parents 24528ef + 6616f27 commit 1a63bfd
Showing 1 changed file with 26 additions and 44 deletions.
70 changes: 26 additions & 44 deletions HipChat Scripts.ahk
Original file line number Diff line number Diff line change
@@ -1,60 +1,46 @@
StatusChangeHC(keys) ; The function that actually does the window switching and change of status
StatusChange(keysHC, keysTeams) ; The function that actually does the window switching and change of status
{
winid := WinExist("A") ; Store ID of current active window
winid := WinExist("A") ; Store ID of current active window

if WinExist("HipChat") ; Check to make sure HipChat is running
if WinExist("HipChat") ; Check to make sure HipChat is running
{
WinActivate
WinActivate ; Not sure why this has to be sent twice, seems to be related to virtual desktops
WinWaitActive, , , 1 ; Make sure window got activated within 1 second
If ErrorLevel ; Run if window did not activate within timeout value
WinActivate ; Not sure why this has to be sent twice, seems to be related to virtual desktops
WinWaitActive, , , 1 ; Make sure window got activated within 1 second
If ErrorLevel ; Run if window did not activate within timeout value
{
MsgBox, 8208, Error, WinWaitActive Timed Out, cancelling
MsgBox, 8208, Error, HipChat Timed Out, cancelling
return
}
} else {
MsgBox, 8208, Not Running, HipChat is not running, cancelling
return
SendInput, ^a%keysHC%{Enter}
}
SendInput, ^a%keys%{Enter}
WinActivate, ahk_id %winid% ; Switch back to original active window
}

StatusChangeTeams(keys) ; The piece that actually does the window switching and change of status
{
winid := WinExist("A") ; Store ID of current active window

if WinExist("ahk_exe teams.exe") ; Check to make sure HipChat is running
if WinExist("ahk_exe teams.exe") ; Check to make sure Teams is running
{
WinActivate
WinActivate ; Not sure why this has to be sent twice, seems to be related to virtual desktops
WinWaitActive, , , 1 ; Make sure window got activated within 1 second
If ErrorLevel ; Run if window did not activate within timeout value
WinActivate ; Not sure why this has to be sent twice, seems to be related to virtual desktops
WinWaitActive, , , 1 ; Make sure window got activated within 1 second
If ErrorLevel ; Run if window did not activate within timeout value
{
MsgBox, 8208, Error, WinWaitActive Timed Out, cancelling
MsgBox, 8208, Error, Teams Timed Out, cancelling
return
}
} else {
MsgBox, 8208, Not Running, Teams is not running, cancelling
return
}
SendInput, ^e
SendInput, %keysTeams%
Sleep, 250 ; Seems to need a delay before sending enter
SendInput, {Enter}
Sleep, 250 ; Seems to be more reliable with a delay before switching apps
}

SendInput, ^e
SendInput, %keys%
Sleep, 250
SendInput, {Enter}
Sleep, 250
WinActivate, ahk_id %winid% ; Switch back to original active window
WinActivate, ahk_id %winid% ; Switch back to original active window
}

^F1::
StatusChangeHC("/back")
StatusChangeTeams("/available")
StatusChange("/back", "/available")
return

^F2::
StatusChangeHC("/dnd On Phone")
StatusChangeTeams("/dnd")
StatusChange("/dnd On Phone", "/dnd")
return

^F3::
Expand All @@ -75,13 +61,11 @@ return
}
FormatTime, var, %var%, h:mm ; format for easy human digestion

StatusChangeHC("/away Back ~" var)
StatusChangeTeams("/away")
StatusChange("/away Back ~" var, "/away")
return

^F4::
StatusChangeHC("/away PM Me")
StatusChangeTeams("/away")
StatusChange("/away PM Me", "/away")
return

^F5::
Expand All @@ -92,8 +76,7 @@ return
return
}

StatusChangeHC("/away " var)
StatusChangeTeams("/away")
StatusChange("/away " var, "/away")
return

^F6::
Expand All @@ -104,6 +87,5 @@ return
return
}

StatusChangeHC("/dnd " var)
StatusChangeTeams("/dnd")
StatusChange("/dnd " var, "/dnd")
return

0 comments on commit 1a63bfd

Please sign in to comment.