Jump to content

Skype Helper


acarvalhomatos
 Share

Recommended Posts

Hi,

Made this script to help my relatives using Skype.

I know there is already 2 libraries for Skype in the forums, but they have either too much or too little stuff. this script fits my needs and i hope you can also use it.

If you want to use it you can easily add more users by changing the UI. also i added loads of comments that will help you navigate the code.

Please comment and review. best regards.

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
Opt("MustDeclareVars", 1)
; Description ...: Helps pc noobs to use Skype.
;  I wanted two older relatives to use Skype, but they do not know anything about computers.
;  They have 3 contacts in Skype, so i created this ui to help them.
;  There is 3 buttons one for each user, depending on if they are online or not I will assign
;   one of two images to the button.
;  This will help my relatives clearly identify the status of the contact.
;   (for this demo it only changes label but the code is there to change image.)
;  Then when the user wants to call anyone he needs to:
;   dial 1 to call user one
;   dial 2 to call user two
;   dial 3 to call user three
;   dial 0 to end Call
;   incoming calls are answered automatically
;  When the call starts video is started automatically and set to full screen.
;   (the same happens for incoming calls)
;  The idea is that this gui is always on top except when call comes.
;  If I detect that Skype has crashed, was terminated by user or internet connection is lost then I minimize the gui.
; Author ........: Andre Matos
; Notes .........:
; ===============================================================================================================================
; ===============================================================================================================================
; Global variables
; ===============================================================================================================================
Global $hGUI, $programName = "Skype Helper", $initStatus = 0
Global $label
Global $user1 = "echo123",$img_online_1="user1_online.bmp",$img_offline_1="user1_offline.bmp",$Button_1
Global $user2 = "echo123",$img_online_2="user2_online.bmp",$img_offline_2="user2_offline.bmp",$Button_2
Global $user3 = "echo123",$img_online_3="user3_online.bmp",$img_offline_3="user3_offline.bmp",$Button_3
Global $oSkype = ObjCreate("Skype4COM.Skype")
Global $oSkypeEvent = ObjEvent($oSkype, "Skype_")
;error handling
Global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Install a custom error handler

main()
;The end
;;;;;;;;;;;;;;;;;
; Skype EVENTS
;;;;;;;;;;;;;
Func Skype_UserStatus($oUserStatus)
;if user changes status to not online and initialization was already done, do initialization again. This can happen if internet goes down.
if not ($oUserStatus = 1 ) and $initStatus = 1 Then do_init()
EndFunc
Func Skype_CallStatus($oCall, $TCallStatus)
  ;if call ringing
if $TCallStatus = 4 Then
  ;focus on skype window if one calls exist meening the incomming call. this is to avoid loosing full scrren when secound call is received
  if $oSkype.ActiveCalls.Count = 1 then $oSkype.Client.Focus
  ;if incomming call then check if not in call already. i do not pay to have video call conference.
  if $oCall.Type = 2 then
   ;if with on call already cancel incoming call
   if $oSkype.ActiveCalls.Count > 1 then
     ;send message to user saying i am busy
     sendBusyMessage($oCall.PartnerHandle)
    $oCall.Finish()
   ;if there is no other ongoing call anwser incoming call
   Else
    ;this workarround is because we receive two events for incoming call that, but on the
    ;secound event the activecall count has decreased. so we need to really check if the call is active or not before anwswering
    For $oCallActive In $oSkype.ActiveCalls
     if $oCall.Id = $oCallActive.Id Then $oCall.Answer()
    Next
   EndIf
  EndIf
;if in progress
ElseIf $TCallStatus = 5 Then
  ;set to full screen
  Sleep(2000) ;delay necessary, the skype ui did not behave well when setting to full screen in the case of incomming call
  Send("!{ENTER}")
  ;if this call allows video and i have web cam then start video
  if $oCall.VideoSendStatus = 1 and not ($oSkype.Settings.VideoIn == '') then $oCall.StartVideoSend()
;if call disconnected
ElseIf $TCallStatus >= 7 Then
  ;bring focus to skype helper if there is no more calls
  if $oSkype.ActiveCalls.Count = 0 then WinActivate($programName)
EndIf
EndFunc
Func Skype_OnlineStatus($oUser, $TOnlineStatus)
update_image_user($oUser)
GUISetState( )
EndFunc
;;;;;;;;;;;;;;;;;
; Skype related
;;;;;;;;;;;;;

Func Wait_for_online()
local $onstatus = $oSkype.CurrentUserStatus
While ($onstatus = 0 Or $onstatus  = -1 or $onstatus = 6 or $onstatus = 7)
  Sleep(1000)
  $onstatus =$oSkype.CurrentUserStatus
WEnd
EndFunc
Func SkypeCOM_Attach()
;keep trying to attach
while not ($oSkype.AttachmentStatus  = 0)
  $oSkype.Attach(5,0)
  Sleep(1000)
WEnd
EndFunc
Func SkypeCOM_StartClient()
If $oSkype.Client.IsRunning Then
  Return 0
Else
  $oSkype.Client.Start()
  Do
   Sleep(250)
  Until $oSkype.Client.IsRunning
  Return 1
EndIf
EndFunc
Func is_ok_for_call($oUser)
Local $onlinestatus = $oUser.OnlineStatus
;if online or away,
if $onlinestatus = 1 or $onlinestatus = 2 Then return 1

;else user not available
;busy will show as offline for example
return 0
EndFunc
Func checkFriends()
Local $oUser
For $oUser In $oSkype.Friends
  update_image_user($oUser)
Next
EndFunc
Func sendBusyMessage($callingUser)
Local $currCallUser = ''
For $oCall In $oSkype.ActiveCalls
  if not ($oCall.PartnerHandle == $callingUser) then
   $currCallUser = $oCall.PartnerHandle
   ExitLoop
  EndIf
Next
; if there was no call at the same time, say you are busy else say who are we talking to.
if $currCallUser == '' Then
  $oSkype.SendMessage($callingUser, "Messagem automatica: Estou ocupado de momemnto")
Else
  $oSkype.SendMessage($callingUser, "Messagem automatica: Estou a falar com " & $oSkype.User($currCallUser).FullName)
EndIf
EndFunc

Func callU($user)
;if in call ignore
if $oSkype.ActiveCalls.Count > 0 then
  Return
EndIf
;if user offline ignore
if not is_ok_for_call($oSkype.User($user)) then
  Return
EndIf

;do Call
$oSkype.PlaceCall($user)
EndFunc
Func endCall()
For $oCall In $oSkype.ActiveCalls
  $oCall.Finish
Next
EndFunc
;;;;;;;;;;;;;;;;;
; GUI related
;;;;;;;;;;;;;
Func update_image_user($oUser)
If $oUser.Handle == $user1 Then
  if is_ok_for_call( $oUser) Then
   ;GUICtrlSetImage($Button_1, $img_online_1)
   GUICtrlSetData($Button_1,$user1 &" online")
  Else
   GUICtrlSetData($Button_1,$user1 &" offline")
   ;GUICtrlSetImage($Button_1, $img_offline_1)
  EndIf
Endif
If $oUser.Handle == $user2 Then
  if is_ok_for_call( $oUser) Then
   ;GUICtrlSetImage($Button_2, $img_online_2)
   GUICtrlSetData($Button_2,$user2 &" online")
  Else
   ;GUICtrlSetImage($Button_2, $img_offline_2)
   GUICtrlSetData($Button_2,$user2 &" offline")
  EndIf
Endif
If $oUser.Handle == $user3 Then
  if is_ok_for_call( $oUser) Then
   ;GUICtrlSetImage($Button_3, $img_online_3)
   GUICtrlSetData($Button_3,$user3 &" online")
  Else
   ;GUICtrlSetImage($Button_3, $img_offline_3)
   GUICtrlSetData($Button_3,$user3 &" offline")
  EndIf
Endif
EndFunc
Func callUser_1()
callU($user1)
EndFunc
Func callUser_2()
callU($user2)
EndFunc
Func callUser_3()
callU($user3)
EndFunc
Func do_init()
if $initStatus = 1 then
  ;I assume skype could have crashed or lost internet connections
  ;remove ui and retry initialization
  $initStatus = 0
  ;remove HotKey
  HotKeySet("1")
  HotKeySet("2")
  HotKeySet("3")
  HotKeySet("0")
  ;minimize window, just to hide from user. assuming no mouse on pc
  GUISetState( @SW_MINIMIZE)
endif
;make sure skype is on before anything Else
SkypeCOM_StartClient()
SkypeCOM_Attach()
Wait_for_online()
$initStatus=1
;check friend status and update ui
checkFriends()

;Shutdowns all calls
endCall()

;adds hot keys
HotKeySet("1", "callUser_1")
HotKeySet("2", "callUser_2")
HotKeySet("3", "callUser_3")
HotKeySet("0", "endCall")

;starts ui
GUISetState( )
;maximises window
GUISetState( @SW_MAXIMIZE)
EndFunc
;;;;;;;;;;;;;;;;;
; Skype API error handler.
;;;;;;;;;;;;;
; This is my custom error handler for Skype API errors
Func MyErrFunc()
;uncomment next line for debug
;MsgBox(0,"sk","error at line =" & $oMyError.scriptline & "windesc" & $oMyError.windescription & " desc = " & $oMyError.description)

;if error detected before intialization is finished
  ;i will not do anything code is prepared to retry same action
;if error detected after initialization
if $initStatus = 1 then
  ;do init
  do_init()
endif

Endfunc
;;;;;;;;;;;;;;;;;
; Main function where all begins
;;;;;;;;;;;;;

Func main()
Local $msg
; Create GUI
$hGUI = GUICreate($programName,900,650,-1,-1,BitOR($WS_MAXIMIZEBOX, $WS_SYSMENU) )
Opt("GUICoordMode", 0)
$Button_1 = GUICtrlCreateButton("Run Notepad", 20, 20, 273, 300, $BS_BITMAP)
$Button_2 = GUICtrlCreateButton("Button Test", 293, -1, 273,300, $BS_BITMAP)
$Button_3 = GUICtrlCreateButton("Run Notepad", 293, -1, 273, 300, $BS_BITMAP)
Opt("GUICoordMode", 1)
$label=GuiCtrlCreateLabel("Dial 0 to disconnect", 120, 400, 500,300)
GUICtrlSetFont($label, 24, 800, "", "Comic Sans MS")

;ui is difined. do initialization
do_init()
; Loop until user exits
While 1
  $msg = GUIGetMsg()
  Select
   Case $msg = $Button_1
    callUser_1()
   Case $msg = $Button_2
    callUser_2()
   Case $msg = $Button_3
    callUser_3()
  EndSelect
  If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
EndFunc
Edited by acarvalhomatos
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...