Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Control Skype without loosing focus on current application?


  • Please log in to reply
10 replies to this topic
V@no
  • Members
  • 37 posts
  • Last active: Jun 15 2008 01:36 PM
  • Joined: 13 Sep 2007
Hello!
I've search this forum for a possible way to asnwer/reject/hangup skype calls without actualy focus on skype window (or loosing focus on current window).
I'm aware of the fact, that Skype already has build-in hotkeys feature and they work well untill you start a game (or maybe other directx application). I belive its the nVidia driver that prevent using hotkeys in games for such applications as Skype (perhaps the way they implemented the hotkeys).
So, after googling around I found AutoHotkey and from what I read it can add hotkeys to the system that would work in games too...(is it true?)

If someone could give an example or something usefull regarding this, it would be awsome :)

Thank you.

V@no
  • Members
  • 37 posts
  • Last active: Jun 15 2008 01:36 PM
  • Joined: 13 Sep 2007
Well, maybe somebody can help me with this example:
#Include CoHelper.ahk
Code= 
( 
  Set oSkype = WScript.CreateObject("Skype4COM.Skype", "Skype_")
  If Not oSkype.Client.IsRunning Then oSkype.Client.Start() End If
  Set oCall = oSkype.PlaceCall("echo123")

  oCall.Hold

  oCall.Resume

  oCall.Finish

  Public Sub Skype_CallStatus(ByRef oCall, ByVal Status)
  End Sub 
)

CoInitialize() 
psc := ActiveXObject("MSScriptControl.ScriptControl") 
Invoke(psc, "Language=", "VBScript") 
Invoke(psc, "ExecuteStatement", Code)
Release(psc) 
CoUninitialize()
I just dont understand why the VBS part does not execute after
Set oSkype = WScript.CreateObject("Skype4COM.Skype", "Skype_")
if I save the part that is in code() as .vbs file, and execute it, it starts skype if not started, and places a call as it should.
So, what do I do wrong here?

P.S. I already registered Skype4COM.dll on the system:
regsvr32 skype4com.dll


V@no
  • Members
  • 37 posts
  • Last active: Jun 15 2008 01:36 PM
  • Joined: 13 Sep 2007
Ok, screw the COM API, its overkill in this case.

So, after wasting entire day trying out different methods and what not, I found that using ControlSend does nothing with skype, but, it works fine with notepad...
Then I've learned that using SendInput (or just Send) works fine with Skype, but it doesnt work when you are in a game, though hotkeys showes in the history.

Anyways, heres my final try make this to work, the script doesnt work right now, but maybe someone can point me in the right direction how to fix it?
#InstallKeybdHook
SendKey(key)
{
	Process, Exist, Skype.exe
	pid := ErrorLevel
	if (pid <> 0) 
	{
		ControlSend,, %key%, ahk_pid %pid% ; Send the keys to Skype
	}
	Else
	{
		SendInput %key% ; No skype is running, send keys to everything else
	}
}
!PgUp::
	SendKey("!&PgUp")
Return
!PgDn::
	SendKey("!&PgDn")
Return
!Home::
	SendKey("!&Home")
Return
!End::
	SendKey("!&End")
Return
!Ins::
	SendKey("!&Ins")
Return

Basicaly I need make the hotkeys work independent on Skype window possition, size, etc and most important make them work if I'm in a game.

Please help.

Thank you!

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007
You may try this. I removed the event as you didn't utilize it. Not tested.

#Include CoHelper.ahk
CoInitialize() 
pSkype := ActiveXObject("Skype4COM.Skype") 
If Not	Invoke(Invoke(pSkype, "Client"), "IsRunning")
	Invoke(Invoke(pSkype, "Client"), "Start")
pCall := Invoke(pSkype, "PlaceCall", "echo123")
Invoke(pCall, "Hold")
Invoke(pCall, "Resume")
Invoke(pCall, "Finish")
;Release(pCall)
;Release(pSkype)
CoUninitialize()


V@no
  • Members
  • 37 posts
  • Last active: Jun 15 2008 01:36 PM
  • Joined: 13 Sep 2007
Thank you very much! your example works fine.
However, when I tryed use the same technique to asnwer a call it wouldn't do anything...Basicaly the Call object does not work as it should...
#Include CoHelper.ahk
CoInitialize() 
pSkype := ActiveXObject("Skype4COM.Skype") 
If Not   Invoke(Invoke(pSkype, "Client"), "IsRunning") 
   Invoke(Invoke(pSkype, "Client"), "Start") 

Invoke(pSkype, "Attach")

!PgUp::
	sCall := Invoke(pSkype, "Call")
	Invoke(sCall, "Answer")
Return

!PgDn::
	sCall := Invoke(pSkype, "Call")
	Invoke(sCall, "Finish")
Return

;Release(sCall) 
;Release(pSkype) 
CoUninitialize()

Thank you!

P.S.
here is VB example from Skype4COM tutorial:
'// Create a Skype4COM object:
Set oSkype = WScript.CreateObject("Skype4COM.Skype","Skype_")

'// Start the Skype client:
If Not oSkype.Client.IsRunning Then oSkype.Client.Start() End If

'// Connect to the Skype API:
oSkype.Attach

'// Run an infinite loop to ensure the connection remains active: 
Do While True 
  WScript.Sleep(60000) 
Loop

'// The AttachmentStatus event handler monitors attachment status and automatically attempts to reattach to the API following loss of connection:
Public Sub Skype_AttachmentStatus(ByVal aStatus)
  WScript.Echo ">Attachment status " & oSkype.Convert.AttachmentStatusToText(aStatus)
  If aStatus = oSkype.Convert.TextToAttachmentStatus("AVAILABLE") Then oSkype.Attach() End If
End Sub

'// The CallStatus event handler monitors call status and if the status is "ringing" and it is an incoming call, it attempts to answer the call: 
Public Sub Skype_CallStatus(ByRef aCall, ByVal aStatus)
  WScript.Echo  ">Call " & aCall.Id & " status " & aStatus & " " & oSkype.Convert.CallStatusToText(aStatus)
  If oSkype.Convert.TextToCallStatus("RINGING") = aStatus And _
    (oSkype.Convert.TextToCallType("INCOMING_P2P") = aCall.Type Or _
     oSkype.Convert.TextToCallType("INCOMING_PSTN") = aCall.Type) Then 
     aCall.Answer() 
  End If
End Sub


Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007
OK, here is a (nearly) verbatim translation of the VB script you attached.
I wrote it mainly as an example to convert VBS to AHK.
As I don't use Skype myself, probably I won't answer any more here.

#Include CoHelper.ahk
CoInitialize() 
pSkype := ActiveXObject("Skype4COM.Skype") 
pEvent := ConnectObject(pSkype, "Skype_")
If Not	Invoke(Invoke(pSkype, "Client"), "IsRunning")
	Invoke(Invoke(pSkype, "Client"), "Start")
Invoke(pSkype, "Attach")

!PgDn::
	Release(pEvent) 
	Release(pSkype) 
	CoUninitialize()
Return

Skype_AttachmentStatus(prms, this)
{
	Global	pSkype
	If	DispGetParam(prms)=Invoke(Invoke(pSkype, "Convert"), "TextToAttachmentStatus", "AVAILABLE")
		Invoke(pSkype, "Attach")
}

Skype_CallStatus(prms, this)
{
	Global	pSkype
	pCall	:= DispGetParam(prms, 0, 9)
	nStatus	:= DispGetParam(prms, 1, 3)
	If	Invoke(Invoke(pSkype, "Convert"), "TextToCallStatus", "RINGING")=nStatus
	AND	(Invoke(Invoke(pSkype, "Convert"), "TextToCallType", "INCOMING_P2P")=Invoke(pCall, "Type")
	OR	Invoke(Invoke(pSkype, "Convert"), "TextToCallType", "INCOMING_PSTN")=Invoke(pCall, "Type"))
		Invoke(pCall, "Answer")
}


V@no
  • Members
  • 37 posts
  • Last active: Jun 15 2008 01:36 PM
  • Joined: 13 Sep 2007
Awsome!
Its working now. Thank you very much!


Since I'm a newbie in all this kind of programming, where one get the proper numbers for DispGetParam() function?
like in your example where did you get "0, 9" from?

Thank you!

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007
You better read it in MSDN:
<!-- m -->http://msdn2.microso...y/aa911974.aspx<!-- m -->

0 here is the 0-based index of the positional parameter, i.e., 0 means the first, 1 means the second parameter of the corresponding function.
9 here is the type of the variant, i.e., 9 is VT_DISPATCH and 3 is VT_I4.
I guessed them from the content of the Sub Skype_CallStatus() in the VBS you attached.

BTW, if you want to use MSScriptControl, don't use WScript specific functions in the script like WScript.CreateObject() in your first example. I think it's the reason why your first code didn't work. You have to at least translate them into the native functions of VBS/JS, e.g., CreateObject()/ActiveXObject().

V@no
  • Members
  • 37 posts
  • Last active: Jun 15 2008 01:36 PM
  • Joined: 13 Sep 2007

I guessed them from the content of the Sub Skype_CallStatus() in the VBS you attached.

Oh, I was afraid you going to say that...:(

Anyways, I got everything working now, just one very little detail I just dont understand why it doesnt work...
For example in VBS/JS it looks like this:
Skype.SilentMode=true;
but when I try use it in AHK - it doesn't work:
Invoke(pSkype, "SilentMode", "true")
How do I set a variable in object?

Thank you for you help!

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

but when I try use it in AHK - it doesn't work:

Invoke(pSkype, "SilentMode", "true")

Use it instead:
Invoke(pSkype, "SilentMode[color=red]=[/color]", "true")

Notice the artificial suffix = in the end of the function name. In the current context, it's unavoidable as there is no native way to differentiate between PropertyGet and PropertyPut. Read it for the detail:
<!-- m -->http://www.autohotke...topic16631.html<!-- m -->

PS. BTW, the last parameter actually should've been something like true, not "true". But, true in VB is different from the BOOLEAN true, so, I actually recommend using "true" as you did. I wrote it just in case if you did it without being aware of it.

V@no
  • Members
  • 37 posts
  • Last active: Jun 15 2008 01:36 PM
  • Joined: 13 Sep 2007
Thank you very much!!!!