#Persistent
#SingleInstance, force
SetBatchLines, -1
ahp=
(
AHKhttp-server 1.0
[var]
)
paths := {}
paths["/GV"] := Func("GV")
paths["404"] := Func("NotFound")
server := new HttpServer()
server.SetPaths(paths)
server.Serve(8000)
;********************************************************************************************************
; Following code opens a GV window at start-up.
;********************************************************************************************************
Loop, 1 ; Set Browser
parm4:=%A_Index%
if (parm4 = "B") or (parm4 = "b")
global browsr:="brave"
else if (parm4 = "E") or (parm4 = "e")
global browsr:="msedge"
else if (parm4 = "F") or (parm4 = "f")
global browsr:="firefox"
else
global browsr:="chrome"
if WinExist("Voice - Settings") ; Does a GV Settings exist?
{
WinActivate
Send !{Left} ; Go Back to GV Calls
Sleep 200
}
;********************************************************************************************************
; Messages window might cause problems, so close it.
;********************************************************************************************************
if WinExist("Voice - ") ; Does the GV Window name contain a phone number?
; The above "Voice - " literal includes an unprintable character after the hyphen
; A match might indicate a Messages/SMS window
{
WinActivate
WinClose ; Close the Window
Sleep 250 ; Script will now open a new Voice Calls window
}
SetTitleMatchMode, 2
if WinExist("Voice") and WinExist("Messages") ; Messages window?
{
WinActivate
WinClose ; Close the Window
Sleep 250 ; Script will now open a new Voice Calls window
}
SetTitleMatchMode, 1
if not WinExist("Voice")
{
Run, %browsr%.exe --new-window "https://voice.google.com/u/0/calls"
WinWait Voice - Calls ; Wait for GV
Sleep 3000
}
WinMinimize, Voice ; Minimize window
return
;********************************************************************************************************
; End start-up code.
;********************************************************************************************************
NotFound(ByRef req, ByRef res) {
res.SetBodyText("Page not found")
}
GV(ByRef req, ByRef res) {
global ahp
SetTitleMatchMode, 1
dialnum:=req.queries["parm1"] ; Get parms
fwdnum:=req.queries["parm2"]
rbutt:=req.queries["parm3"]
if fwdnum is not integer
fwdnum=1
if WinExist("Voice - Settings") ; Does a GV Settings exist?
{
WinActivate
Send !{Left} ; Go Back to GV Calls
Sleep 200
}
;********************************************************************************************************
; Messages window might cause problems, so close it.
;********************************************************************************************************
if WinExist("Voice - ") ; Does the GV Window name contain a phone number?
; The above "Voice - " literal includes an unprintable character after the hyphen
; A match might indicate a Messages/SMS window
{
WinActivate
WinClose ; Close the Window
Sleep 250 ; Script will now open a new Voice Calls window
} ; Script will not recognize a Window name that contains a phone number
SetTitleMatchMode, 2
if WinExist("Voice") and WinExist("Messages") ; Messages window?
{
WinActivate
WinClose ; Close the Window
Sleep 250 ; Script will now open a new Voice Calls window
}
SetTitleMatchMode, 1
;********************************************************************************************************
; Following code processes a call using an existing GV window.
; This is normal call processing.
;********************************************************************************************************
if WinExist("Voice") ; Does a GV window exist?
{
WinActivate
WinGetPos, X, Y, W, H, A ; Get coordinates of window
M1 := (W//1.015) ; MouseClick 1.5% from right edge of window
M2 := (A_ScreenHeight//2.9) ; and 1/3 of screen height from top edge of window
FlatWin := "N"
if (H < A_ScreenHeight*.47) ; Window height less than 47% of screen height?
; When window is very flat it scrools when tab to number field
; This causes subsequent calls to fail
{
SendInput #{Up} ; Maximize window - fixes above peoblem
M1 := (A_ScreenWidth//1.015) ; MouseClick 1.5% from right edge of window
FlatWin := "Y"
Sleep 200
}
If (rbutt="R") or (rbutt="r") ; Mouse buttons switched?
MouseClick, Right, %M1%, %M2% ; Reposition cursor so only 1 tab needed for next step
else
MouseClick, Left, %M1%, %M2%
Sleep 250
SendInput {Tab} ; Tab to outbound number field
Sleep 100
SendInput %dialnum% ; Type outbound number
SendInput {Enter}
Sleep 1000
}
;********************************************************************************************************
; End existing window code.
;********************************************************************************************************
else
;********************************************************************************************************
; When script can't find a window name beginning with "Voice"
; opens a new GV window to process a call
; This happens when the GV window is closed or settings, etc., was clicked.
;********************************************************************************************************
{
if (StrLen(dialnum) = 10) ; Outbound number 10 digits?
dialnum := 1 . dialnum ; Add country code, otherwise will be treated as international call
Run, %browsr%.exe --new-window "https://voice.google.com/u/0/calls?a=nc`,`%2b%dialnum%"
WinWait Voice - Calls ; Wait for GV
;********************************************************************************************************
Sleep 2500 ; Pause until GV page fully loads
; This value works with with a 1st gen I3 and faster CPU's
; Slower computers might need to increase this value
;********************************************************************************************************
WinGetPos, X, Y, W, H, A ; Get coordinates of GV window
M1 := (W//2) ; Calc coordinates of approx middle of window
M2 := (H//2)
If (rbutt="R") or (rbutt="r") ; Mouse buttons switched?
MouseClick, Right, %M1%, %M2% ; Position cursor to middle of window for forwarding# selection
else
MouseClick, Left, %M1%, %M2%
Sleep 600
}
;********************************************************************************************************
; End new window code.
;********************************************************************************************************
;********************************************************************************************************
; Start of common code for new & existing GV window.
;********************************************************************************************************
SendInput {Tab} ; Tab to forwarding number selection
SendInput {Enter} ; Enter to display the forwarding numbers
Sleep 250
;********************************************************************************************************
; The script will use parm2 (fwdnum) to select the forwarding number
; Valid numbers are 1, 2 or 3
; It will select the 1st when fwdnum is invalid or not specified
;********************************************************************************************************
if (fwdnum=2) ; Position cursor to 2nd forwarding number
{
SendInput {Down}
Sleep 100
}
if (fwdnum=3) ; Position cursor to 3rd forwarding number
{
SendInput {Down}
Sleep 100
SendInput {Down}
Sleep 100
}
SendInput {Enter} ; Enter will select the forwarding number
Sleep 500
SendInput {Tab} ; 2 tabs to "Connect" button
SendInput {Tab}
Sleep 100
SendInput {Enter} ; Enter to initiate callback
Sleep 1500
if (FlatWin = "Y")
SendInput #{Down}
Sleep 1500
WinMinimize ; Minimize window
res.status := 200
}
;********************************************************************************************************
; End common code.
;********************************************************************************************************
#Include %A_ScriptDir%\AHKhttp.ahk ; File muat be in same folder as Script
#Include %A_ScriptDir%\AHKsock.ahk